Saturday, March 3, 2018

Use Action to retrieve or update data in an unrelated entity in Dynamics 365 Workflows

There are scenarios where you need to access data from an entity that is not directly related to the entity for which you are building a Workflow in Dynamics 365.

For example, you want to send an email alert to the Owner of the Account on the Opportunity when an Opportunity Line is created or updated with the amount exceeding $10,000. In this case, the Workflow will be created for the Opportunity Line entity which triggers the Workflow. However, within the Workflow Designer, you can access data only from the entities that are reated to Opportunity Line entity such as Opportunity or Product. However, Account is not directly related to the Opportunity Line entity and therefore you cannot access the Owner field of the Account within the Workflow. To get around this limitation, you can create another Process of type Action. The Action will be for the Account entity and it will return the Entity Reference for the Account being passed to the Action. You can then call (perform) this Action within your Workflow. This will enable you to access any fields from the Account entity within the Workflow. Here are the specific steps to implement this solution.
Create a Process of type Action on the Account entity.
Add an Argument of Type EntityReference returning the Account entity as Output.


Add the Assign Value step as shown in the screenshot below.


Activate the Action.
Next, create a Workflow for the Opportunity Line entity.
Select "Record is created" and "Record fields change" (Line Amount) triggers.
Add condition. In this case it is: if Opportunity Line:Amount > 10,000.
Add the Perform Action step and select the Action created above.


Pass the Account on the Opportunity as the Input parameter.
Add the Send Email step.

As you can see from the screenshot below, you can now access the Owner field on the Account to populate the “To” (email recipient) in the Send Email step.
Complete the other details for your email.
Activate the Workflow and test your Workflow by adding or updating a line on the Opportunity exceeding $10,000.
You can use this Action in other Workflows or code where you need to retrieve data from a specific Account record.

In addition, you can use this technique to update an unrelated record in your Workflow which was not previously possible.

You can also use this technique to retrieve data from the Business Unit of the record owner
or Field Service Settings which are not directly related to the record on which the Workflow is being executed.

In this post, we saw how you can retrieve or update data in an unrelated entity within the Workflow using Action.