Workflows are extremely powerful. Especially when used in combination over several Entities. Unfortunately when doing so, infinite loops often become a blocking issue. Fortunately by bringing flags into the mix, we can prevent such infinite loop situations.
Example: Searchable Automated Archive
Dynamics 365 comes out-of-the-box with an Audit Trail. By that you can look into the history of certain Fields. Perfect for system administrators, but useless to end users.
Sometimes users need a user friendly archive for heavily used Fields in CRM. A feature that quickly answers: “who changed what by when”. This article will explain a user friendly non-coding alternative to the Audit Trail based on the Out-of-the-Box Text-Only Field on Opportunity called “Current Situation”.
Here is how
Step 1 – Create Entity
Create a new Entity called “Situation Archive”:
Step 2 – Create 3 Fields on Situation Archive
On the newly created “Situation Archive” Entity add the following 3 fields:
- Create a Lookup Field referencing the “Opportunity” Entity:
- Create a Multiple Line Text Field called “Situation”:
- Create a Two Options Field called “Is Created By Workflow”:
Add the newly created Lookup and Multiple Line Text Fields to the Form:
Step 3 – Make Relationship Parental
Navigate to the N:1 relationship you just created on “Situation Archive” pointing to “Opportunity” and set its behavior to Parental:
Step 4 – Create Field on “Opportunity”
Create a new Two Options Field called “Is Updated By Workflow” on the “Opportunity” Entity:
Step 5 – Create Workflow on “Situation Archive”
Create a workflow on the Entity called “Situation Archive” that updates its parent Opportunity whenever a new Archive record is created:
Workflow Step: Set Name
Make sure to set a Name for the record (don’t forget to make the “Name” Field Optional first):
Workflow Step: Update Opportunity (part 1/2)
Update the “Current Situation” Field on the parent Opportunity based on the input given by a User on the “Situation Archive” Entity level:
Workflow Step: Update Opportunity (part 2/2)
Set the flag that the latest change to the Opportunity was made by a Workflow Activity. This will prevent the infinite loop situation!
Step 6 – Create Workflow on “Opportunity”
Create a workflow on the “Opportunity” Entity that creates a child “Situation Archive” record whenever the “Current Situation” Field changes:
Workflow Step: Create Archive Record
Properly populate the new “Situation Archive” record, whilst setting its flag that the record has been created by a Workflow Activity. This is what will prevent an infinite loop!
Workflow Step: Set Flag back to FALSE
This step only occurs when the Workflow is triggered by another Workflow. By Setting the flag back to “No”, following user input will allow the Workflow to be triggered again, whilst currently preventing an infinite loop situation!
Step 7 – Add Subgrid to Opportunity Form
To be able to experience the end result, add a “Situation Archive” Subgrid to the “Opportunity” Form:
Use the following Subgrid properties:
Result: Synced Field vs. Subgrid
Users can change the “Current Situation” Field and/or create a new “Situation Archive” record using the Subgrid, without causing an infinite loop situation: