Microsoft Dynamics CRM 2011 – Workflows Wait and Timeout


When we come across adding any kind of wait conditions in our workflows, we only think of Wait and not Timeouts. We need to be careful when choosing either one of them.

They both seen to be the same, but they do serve different purpose. Depending on the requirements, one of them can perform better and accurately as per what we need.

Wait is more dependent on a value in a field which is not of a type date or time. Wait postpones a workflow until a condition changes depending on a value in a field. For example Wait until the “Approval” field is set to “Yes” by the manager. On the other hand Timeout is more dependent on date and time. Timeout postpones a workflow until a date/time condition relative to a value in a specified CRM record’s date/time field.

1) Timeout:

Timeout is more date and time related.

For example, there is an entity called Movies. Every time an admin user adds a new movie record, an email needs to go out to a Manager. The email will request the Manager to validate the data and approve the movie record. This email will be sent after 2 days of the record being created. In these 2 days the admin user can edit the movie data as many times as required. After the manager approves the record, there is a radio button field called “Approved” which will be set to “Yes”.

Step 1:

I will create a workflow for this timeout scenario. I have opened my unmanaged solution called Movies. I will go to my Processes section and click on New to create a workflow.

Add a New Workflow

Add a New Workflow

Step 2:

I have entered all required fields for my workflow. I will call my workflow “Approve a new Movie”. The workflow will timeout, until 2 days after it has been created. Exactly after 2 days, it will send an email to the Manager for approval.

New Workflow Details

New Workflow Details

Step 3:

This workflow starts on an event when a Record is created. Inside the workflow UI designer, I will add a new Step. The step is a Wait Condition.

Note: The step for Timeout is within the Wait Condition but we can specify it as a Timeout condition. Timeout is a kind of Wait, and the workflow is in sleep mode till a particular date/time condition is met.

Add a New Step

Add a New Step

Step 4:

The Wait Condition step is added. I will name it “Approve the Movie”. I will now “click to configure”. This will bring “Specify Condition” window.

Edit Condition

Edit Condition

Step 5:

I will add a condition. I will select a condition of Timeout till Process is over 2 Days after the record is created. The condition of “2 days after Created On” is selected on the right hand side under Dynamics Values. Click “Save and Close” button.

Timeout Condition

Timeout Condition

Step 6:

Now we have a Timeout condition. I will add a step of emailing the manager if the Timeout condition is met.

Timeout Condition Created

Timeout Condition Created

Step 7:

Add a step to send an email. I will name this step as “Email Manager”.

Step of Emailing Manager

Step of Emailing Manager

So what I have done above is to have the workflow timeout until 2 days after a new Movie record has been created. As soon as a new Movie record is created, a new instance of this workflow will be created and immediately go in sleep mode or timeout mode. The workflow will do nothing till the 2 days have passed. These 2 days are taken from the Created On date and time. After 2 days, the workflow will execute the next step of sending an email to the manager.

Step 8:

Now let’s take the same scenario and have a Wait condition instead of a Timeout condition. I have modified my workflow to look like below.

Wait instead of Timeout

Wait instead of Timeout

The above condition states the workflow to wait until Created On is less than 2 days after the movie record has been created. This Wait condition looks a bit odd as compared to the usual looking Timeout condition. This is because Wait is more for non-date and non-time conditions based on a value of a field. If we run the above Wait workflow, it might not run exactly 2 days after. The workflow may run after 1 hour of the condition being met. So in our date and time scenario Timeout works best.

2) Wait:

Now let’s take a second scenario. We need to email the record owner of the Movie as soon as the manager approves this record. This could have been handled by a simple workflow which runs after the status of the Approved field changes to Yes. When a manager approves and saves a record, this workflow will fire. For my demo purpose, I will modify the logic a bit and introduce a Wait condition.

Step 1:

The workflow which I am creating below will execute whenever a new Movie record is being created. After an instance of workflow is created, it will go in a Wait condition. This Wait condition will postpone the workflow till the Manager approves this record. Below is a new workflow.

New Workflow for Wait Condition

New Workflow for Wait Condition

Step 2:

This workflow will start when a Movie record is created. Inside the workflow UI designer, I will add a new Step. The step is a Wait Condition.

Add a New Wait Step

Add a New Wait Step

Step 3:

I will now “click to configure”. This will bring “Specify Condition” window.

Edit Wait Condition

Edit Wait Condition

Step 4:

Here I create and add my Wait condition. The condition is to Wait until Approved field is Equal to Yes. Click “Save and Close” button.

Wait Condition

Wait Condition

Step 5:

This will create the Wait condition. I will name it “Wait till the Movie Record is Approved”.

Wait Condition Created

Wait Condition Created

Step 6:

I will add a step of emailing the owner of this movie record. I will name this step as “Email the Record Owner”.

Email the Record Owner

Email the Record Owner

We finish creating the workflow for the Wait condition.

For a new movie record, a new workflow instance gets created and goes into Wait state. Whenever manager approves and saves the record, immediately the workflow will come out of sleep mode. Workflow will check whether the record is approved. If “Yes”, then email the record owner informing of the approval. In this scenario the Wait condition is more suitable than timeout, as the field value is non-date and non-time.

I hope this blog about ‘Microsoft Dynamics CRM 2011 – Workflows Wait and Timeout’ was informative. Please feel free to leave your comments.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Comments

  • Emad Mustafa  On April 26, 2012 at 5:58 AM

    Hi Ashish, Thank you for this good blog.
    I wanted to tell you that I am trying to apply same timeout but with Modified On date, I am not sure when we apply any changes\update field using workflow that Modified On get effected. did you ever tried to apply time out to on modified on date.

    • Ashish Mahajan  On April 26, 2012 at 12:55 PM

      Hi Emad,

      I am glad you like the blog.

      The answer to your question is yes, the principle is same.

      Whenever you make any changes (updating a field value) in the entity record’s fields, then “Modified On” will reflect the Date and Time when the form was saved.

      The “Modified On” will also change if you are updating fields of an entity record through a workflow. Try testing this on an on-demand workflow (by changing a field value) and you will see that the “Modified On” has changed.

      I hope this answers your question.

      cheers,

  • Shruti  On October 26, 2012 at 2:57 AM

    Hi Ashish,

    This is a veru good blog, i have similar requirements to create a workflow and notify owner when lead record is assigned to them. if it is untouched for 3 days i would like to send them reminder message and another reminder after 2 days and copy their manager.
    Can you please help with this workflow?

    Thanks
    Shruti

    • Ashish Mahajan  On October 28, 2012 at 1:35 AM

      Hi Shruti,

      Thank you and I am glad you liked the blog.

      You can create the workflow and use Timeout condition. On your lead record, you identify a field (system or custom) which can define that the lead was touched by the assigner of the lead. For example let’s say you have a custom two option field which has label “Lead work completed” with values Yes/No. You can also take any system field (lead attribute).

      Now in your workflow first step is to email and notify the assigner of the lead.

      Then put an IF condition with Timeout to check process timeout equals 3 days after created on (for that lead) and also if the “Lead work completed” is NO, then send 1st reminder.

      Put a second condition with Timeout to check process timeout equals 5 days after created on (for that lead) and also if the “Lead work completed” is NO, then send 2nd reminder.

      I hope this helps.

      Kind Regards,
      Ashish

  • Francis  On November 1, 2012 at 8:39 PM

    Hi ashish,

    Yr blog really saved my day.
    I have one similar requirement , instead of directly giving after 2 days, 3 days i want to take this hrs from another entity.
    which means in workflow on creation of entity i need to send an email based on escalation time mentioned on lead form.i need to capture that escalation time here EG: ESc time – 12 …then i need to send an mail after 12 hrs..How to do this?

    Thanks for any help

    • Ashish Mahajan  On November 2, 2012 at 11:33 AM

      Hi Francis,

      This can be done with the help of DotNet programming. In your workflow you will have to create a custom workflow activity step. In the custom workflow activity, you take the time when this workflow is fired. I mean take the date and time at that instant. Put this date and time into a variable. Add 12 hours to that date and time variable. Expose this variable from the custom workflow activity (will be an output variable). This variable will be available in your workflow to be used. After this custom workflow step, put an ‘IF’ statement step in your workflow. This ‘IF’ will check for the “Process Timeout” equals to your variable. So this means only when your workflow will reach the date and time in your variable, it will send the escalation email. So basically your Timeout will be evaluated not against system fields like CreatedOn and ModifiedOn, but against your output variable (which was created by your custom workflow activity).

      I hope this helps. You need to create that variable which will store date and time by adding +12 hours to the current date and time.

  • Francis  On November 1, 2012 at 8:49 PM

    Hi ashish,

    Yr blog really saved my day.
    I have one similar requirement , instead of directly giving after 2 days, 3 days i want to take this hrs from another entity.
    which means in workflow on creation of entity i need to send an email based on escalation time mentioned on lead form.i need to capture that escalation time here EG: ESc time – 12 …then i need to send an mail after 12 hrs..How to do this?

    Thanks for any help

    • Ashish Mahajan  On November 2, 2012 at 11:34 AM

      Hi Francis,

      This can be done with the help of DotNet programming. In your workflow you will have to create a custom workflow activity step. In the custom workflow activity, you take the time when this workflow is fired. I mean take the date and time at that instant. Put this date and time into a variable. Add 12 hours to that date and time variable. Expose this variable from the custom workflow activity (will be an output variable). This variable will be available in your workflow to be used. After this custom workflow step, put an ‘IF’ statement step in your workflow. This ‘IF’ will check for the “Process Timeout” equals to your variable. So this means only when your workflow will reach the date and time in your variable, it will send the escalation email. So basically your Timeout will be evaluated not against system fields like CreatedOn and ModifiedOn, but against your output variable (which was created by your custom workflow activity).

      I hope this helps. You need to create that variable which will store date and time by adding +12 hours to the current date and time.

  • Francis  On November 2, 2012 at 3:40 PM

    Thanks AShish,
    i wil try today on what you have said.
    Before that, can you pls explain what is the D.B workflow and custom work flow activity ? and is custom work flow and plugins are same?

    Francis

    • Ashish Mahajan  On November 4, 2012 at 9:55 PM

      Hi Francis,

      In Dynamics CRM when you create a workflow through the CRM workflow wizard, it is called as out of the box workflow. Sometimes the workflow has limitations such as complex calculations or fetching some values from another entity. In those scenarios you write a custom workflow activity which is a .NET assembly. This you can register that .NET assembly as a workflow step and use it in your out of the box workflow.

      You can search for these terms on Google and you will get tons of example. You can also download Microsoft Dynamics CRM 2011 SDK which has plenty of examples and code.

      • Francis  On December 14, 2012 at 3:33 PM

        Hi Ashish,

        Thanks for the suggestion..and sorry for very delayed reply.I have a question.hope u wont mind in answering in this topic.Is it possible to filter picklist?Eg: i have city names like Mumbai, chennai, kolkata , bangalore, and hyderabad.in my picklist.is there anyway i can only display few items by making some items disable..or by making few items inactive by setting a flag r something? in my understanding i can use look up and add additional column like flag and make few items as Y and i can only show the items by filtering items with Y…but ido not want to change that field to lookup as there are lots of dependencies are in this dropdown already.Pls.Suggest

      • Ashish Mahajan  On December 17, 2012 at 9:20 AM

        Hi Francis,

        Please use JScript (JavaScript) to filter your pick list. If you search on Google on this topic, you will find lots of code for CRM version 4.0 and 2011.

        You can use any of these codes and customize as per your requirement.

        cheers,

  • Muddasir Mohammed  On November 13, 2012 at 5:54 PM

    Hi Ashish

    I have a similar scenario but a different approach. I want to create reoccurring tasks in a project as soon as the task is completed. I want to do this using the workflow in CRM 2011 but not sure how to do it. Please help me

  • Eswar  On November 13, 2012 at 10:39 PM

    Hi everyone , do we have any limitation for timeout field like it needs to be a Datetime or can be a date filed ? Because am having the similar requirement and am excluding holidays and saturday & sundays in one of my custom workflow and resulting the next working day . Now am setting the result date value from my custom workflow and setting this date as the timeout value . But as soon as i active the workflow , this step is rolling back and setting to Execution Time of the process.
    Please Help me in this .

  • Eswar  On November 13, 2012 at 10:41 PM

    Hi Ashish ,

    WF Presentation is really good ,

    Does the 2 days mentioned in the step will exclude Business Closure days which we configured in our CRM ?
    Help me on this ..

    • Ashish Mahajan  On November 18, 2012 at 10:52 PM

      Hi,

      The 2 days mentioned include all days (weekends and business closure days).

      • Julie Dillon  On May 17, 2013 at 2:18 AM

        Is there a way to exclue weekends and business closures? Do you need custom code for this? Thank you!!! Julie

      • Ashish Mahajan  On May 19, 2013 at 8:52 AM

        Hi Julie,

        There is no inbuilt way to exclude weekends and business closures. For weekends and business closures you have to write a custom workflow activity. Either you write your own workflow activity or use a third party library. I have used a free library and is very good: http://manipulationlibrary.codeplex.com/. In this use the function “Add Business Days”. There are many more useful functions.

        One drawback is that the business closure holidays don’t work for different states of a country. For example in Australia certain holidays fall on different dates in different states. If you also want to tackle this scenario, then create 2 custom entities, called HolidayState and HolidayDays. HolidayState will have all states and HolidayDays will have date and the HolidayState lookup. Include these 2 entity data in your own custom workflow activity code.

        I hope this helps.

      • Julie Dillon  On May 22, 2013 at 9:26 AM

        Thank you Ashish! Now I have run into another issue around sending automated emails from the CRM workflow function… that pesky Tracking Token Number. Now here’s the problem: my company uses the Service/Case Module heavily and prefers to keep that number in their email subjects for accurate tracking purposes. I am a marketing person and do not want to use this function. How can I exclude the Tracking Token Number from my marketing emails while retaining this functionality for the Service department?

      • Ashish Mahajan  On May 26, 2013 at 6:40 PM

        Hi Julie,

        You cannot turn it off for just one CRM module (CRM section) or just one entity, in a supported way.

        You can read more about CRM email token in these articles:

        http://crmbusiness.wordpress.com/2012/10/29/crm-2011-understanding-email-tracking-tokens/

        https://community.dynamics.com/crm/b/dynamicscrmsupportblog/archive/2012/08/14/email-tracking-token-in-dynamics-crm-2011.aspx

  • Dayo  On June 6, 2013 at 8:22 AM

    Good job! Please i need your help in creating a step in a workflow I created. I have created a workflow that turn email to case but I want to add a step that will reply the email sender after the status of the case is changed

    • Ashish Mahajan  On June 11, 2013 at 1:11 AM

      You should be able to do so. When you are running a workflow on an email, and creating a new case out of the workflow, the email values should still be available.

      Please let me know if this is not the case. In that case let me know this issue in more detail.

  • Mano  On September 5, 2013 at 1:10 PM

    Hi Ashish,

    Your blog is very useful for me to create Workflows for email alert.

    Now I have a custom entity called ‘Asset’. This contains the product details and customer with product ‘expiry date’. So, I need a workflow with following steps:
    1. wait until 2 months before expiry date
    2. Create Opportunity with the product and customer details in Asset.
    3. Send email alert to customer about the expiry and request them to do a service. Meantime cc the same email with set regarding the above created opportunity.

    Is it possible to check multiple Asset for same customer and Create one opportunity for all the Asset belonging to the customer and send one email to the same customer.

    Thanks,
    Mano

  • Sarfaraj Shaikh  On September 9, 2013 at 8:21 PM

    Hi Ashish,

    I am using a CRM workflow with timeout condition. For testing purpose i use a timeout value of 5 mins (Which in actual on production is 1 day). It was working fine and i was able to change this timeout duration as and when needed. Recently we had upgraded to UR14.
    Now when i try to edit htis duration i do not get option of timeout as a drop down in it Edit page, nor duration on the right selection pane.
    I then require to drop this step and add new wait step.
    Please can you guide me on this as deleting step removes all sub steps written it them.

    Regards
    Sarfaraj Shaikh

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: