In This Article

    Share

    How to Use Recursive Workflows in Dynamics 365 for Customer Engagement

    Dynamics 365 for Customer Engagement allows users to create workflow processes.  Workflow processes are a very powerful, highly flexible toolset for manipulating data and building automation.  They can be used to automate email notifications, dynamically create and update records, and affect most entities in Dynamics 365 for Customer Engagement, often without any user interaction.

    In Dynamics, workflows typically work based on triggers, such as the creation of a record, the change of a record’s status, the assignment of a record, the update of a record’s fields, or the deletion of a record.  However, all of these triggers require some kind of change to the record in order to work, which is not always possible.

    Before we start, is your team looking for a D365 managed services partner to provide post go-live support and preventative maintenance? For information on our 24/7 support download our Managed Services Overview.

    For example, what if we want to create an email reminder that a case is still open for the case owner?  What if we want to reassign a case if it is inactive for too long?  What if we want to auto-close a case if there has been no response from the customer after a certain period of time?

    To accomplish these kinds of functionalities, we can rely on recursive workflows.  Recursive workflows are workflows which loop by calling themselves as child workflows.  While recursive workflows can be very complex, they typically consist of three core pieces:

    1. The end condition(s)
    2. The action to repeat
    3. The action to trigger itself

    How to Build a Recursive Workflow

    Let’s build a workflow that solves one of the scenarios above: create an email reminder that a case is still open for the case owner.

    1. Create a new workflow. Make sure the workflow runs in the background.  In Dynamics 365 for Customer Engagement, real-time workflows cannot have wait conditions, which we’ll be using later on.
    2. Set the workflow to start when “Record is created” and “Record status changes.” Also, allow it to activate “As a child process.”
    3. Add a Check Condition for Case having a status of Cancelled or Resolved and with the Step “Stop workflow.” This will be our end condition.
    4. Add a Wait Condition and set it for a duration of 5 minutes.
    5. Add a Step “Send Email” and define the reminder you want to send. The recipient should be the owner of the Case record.
    6. Add a Step “Start Child Workflow” and select the same workflow. You may need to save your workflow before you can complete this step.
    7. Your completed workflow should look something like this:

    Go ahead and Activate it.

    Now we can take a look at our Case and see the workflow in action.  As you can see in the image below, the notification has been sent quite a few times since the workflow was activated.  It looks like our workflow is working as intended!

    However, when we check out our System Jobs, we see a slightly different story.

    After a few executions, our workflow has failed.  This is because Dynamics 365 for Customer Engagement has a built in safeguard to prevent infinite loops, which can severely bog down the system.  If a workflow calls itself more than seven times within an hour, the eighth attempt will fail.  To fix our workflow, simply set the duration to something more reasonable.

    And there you have it.  All fixed!

    In this simple example, we only used one repeated action – sending a notification email.  Recursive workflows do much more than that though.  Every action between the end condition(s) and the start child workflow step will be repeated and combined with various workflow functions.  For example, if we wanted to count how many times a reminder is sent, we would only need a number field and an action step to increment that field each time the workflow runs.  Taking it a step further, we can perform additional actions based on that count, such sending different notifications emails based on the number of emails already sent or automatically escalating the case after a certain number of reminders.

    For additional questions on Dynamics 365 workflows, please contact Hitachi Solutions today.