Saturday, 6 April 2013

Dynamics CRM 2011 – Send an e-mail on a specific date

 

Currently, I came across a scenario where we had to configure a workflow to send an e-mail on a specified date value on an opportunity entity. On opportunity entity I had a date field “Date 1” and what we were required to do was to send an email to opportunity owner on a date specified in the Date 1 field value. To achieve this, I can configure a workflow with timeout or wait condition set on the Date 1 value.

First, I tried to make it work using the Timeout criteria but it seemed to fail our requirements when the date value is null. So, I decided to work with wait condition.

Following are the steps configured in workflow to meet the requirements:-

image

Step 1: Start workflow on Record Created and Record Fields change. In Record fields change select the Date1 field.

Step 2: Check if Date1 field is null. If the field is null then no need to set any wait condition.

Step 3: Since we have fired this workflow on field change also, we had to make sure that there should not be more than one workflow with wait condition. When opportunity record is created and Date 1 field contains data, a workflow record would be created in wait mode. At the same time, if somebody modifies the date 1 value for the same opportunity record then another workflow record should not be crated in waiting mode to be executed on that particular updated date value. Instead, the previously created workflow should be updated with new value. To achieve this we have taken a custom attribute here DateValue which is a two option field. Default value of DateValue is false. Once a date is entered the value of datevalue gets updated to true. This way we ensure that on field change we don’t create a new wait condition if one already exists.

Step 4: If the attribute value is false means there is no previously existing system job with wait condition. So, Add step of wait condition and set process execution time on or after the Date1 value. If the value is true means the workflow record was already created and nothing to do in that scenario.

Step 5: Add a Send Email step and configure required values.

I hope this would be helpful.

6 comments:

  1. Hi Ankit,

    Thanks and it's really very helpful topic.

    I got one doubt here, when user updates that Date 1 field then it will not create the another instance of the workflow but it won't send an email on the updated Date 1 field value. It will send the email on the old value.

    Please specify how we can avoid this issue.

    ReplyDelete
  2. Hello Prakash,

    When you update the date 1 field value, the above workflow will be triggered. At this time it will change the existing workflow date and won't create a new e-mail activity as the value of the custom attribute DataValue will be "Yes"(true). You could also add one more step in above workflow about the date condition like Date 1 value should always be greater then today's date. Furthermore, we have setup this workflow with the "Automatically delete completed workflow jobs" option. So, on successful execution, the workflow instances will be deleted.

    ReplyDelete
    Replies
    1. Hi Ankit,

      I agree with your explanation but the last step you have specified for the Wait condition is not working when i tested it at my side, My workflow is getting postponed until 12/4/9999. I guess you should go with "Process Timeout equal to New date".

      Can you please provide me screenshot in which workflow is waiting for some specified time period with your wait condition.

      Regards,
      Prakash Omer

      Delete
    2. Hello Prakash,

      When you use the "wait until" condition, dynamics CRM takes the date with the year as 9999. However, if you are working on development machine and could change the server date to the future date (the same that we set just before), the workflow will trigger and send the e-mail on that time. Please validate and share your feedback.

      Delete
    3. I agree with your explanation but the last step you have specified for the Wait condition is not working when i tested it at my side, My workflow is getting postponed until 12/4/9999 (Infinite time period). I guess you should go with "Process Timeout equal to New date".

      Can you please provide me screenshot in which workflow is waiting for some specified time period with your wait condition.

      Regards,
      Prakash Omer

      Delete