Deep Workflow Queries

Workflow designer is slow and ancient but it still have to be used if you don’t want to pay for the Flow or simply want to create custom Action. It lacks several features but still flexible enough to work around some of builtin limitations.

One of such things is deep data queries. Lest say you are cooking a Workflow or Action bound to Opportunity. Designer let you to access all related N:1 records such as Account, Contact or SystemUser. But what if you need to access entity related to these related entities? For example to parent account of account or to Opportunity owner’s boss?

At first sight it seems to be impossible and usually this cases are solved with custom Workflow activities (not to be confused with custom Actions). But why not Actions?! Actions don’t require programming but still can be used in workflows since CRM Online 2015 Update 1. Let’s find out how to solve this problem using Actions!

I will use Product for this example but the idea itself works for any entity.

Step 1. Create custom Action for Product entity

createaction

It’s always a good idea to have some naming convention for Actions of Workflows especially if they are created in technical purpose. For this kind of processes I use “Lookup” prefix but this is fully optional.

Step 2. Disable rollback

disablerollback

This step is optional but its always better not to use rollback if you are not going to modify data. If rollback is disabled Action should be executed outside of transaction what is faster and more efficient.

Step 3. Add output parameter

addoutput

Now we need to add output parameter of type EntityReference as we are going to “find” and return Product. The name is up to you but I recommend to use same name as for primary key attribute. What is important is to select Entity type for this parameter! In this case Entity must be Product.

If you forget to select entity type your Action will not be visible in Workflows!

This behavior is not documented but you can learn more about restrictions here: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/create-own-actions#execute-an-action-using-a-process

Step 4. Set output value

Now, since we have output parameter, we have to assign its value! That can be done by selecting the Assign Value item in the Add Step drop down.assignvalue

The most funny part is what we are going to set input parameter value as output value! Yes, that’s right. Our Action has Product as primary entity so it has hidden input parameter named “Target” type of EntityRererence. All we need to do is to pass input value to output.

But what for? Easy. If you add a step to a process and this step has output value, this value will be available to use in next steps.

Step 5. Run "Lookup: Product" from other process or Action

Now we need to run our custom action from consumer process. That can be done by selecting the Perform Action item in the Add Step drop down.

consume

Now you can pass Product reference from any field you want to this Action and entity itself will be visible as process variables:

select

Step 6. Enjoy!

Stay tuned!

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.