locked
Crm 4.0 Workflow on custom entity to send email on due date column RRS feed

  • Question

  • Hello All,

       could you please help me how to write a workflow on custom entity to send/trigger an email to customer saying, subscription has been canceled when the system date crosses the due date column of custom entity and sends email before 1 week notifying email to  the customer asking  to reactivate the subscription before due date.

    Monday, August 30, 2010 6:39 PM

Answers

  • Workflows can "timeout until" a particular date, and the condition operators would allow you to use this to specify any duration before or after a date stored in CRM.  You can provision your workflow with two "timeout" conditions, one for a week before the stored date, and the other for the date itself.  To do this:

    1. Click on Add Step and select "Wait condition".
    2. Click on the condition to configure it.
    3. Select "Workflow" from the entity picklist.
    4. Select "Timeout" from the attribute picklist.
    5. Select "Equals" from the operator picklist.
    6. In the Dynamic Values box, specify 7 "Days" and "Before", and then select the attribute that contains your stored date.
    7. Save and Close the condition page.

    You may now add an email action as a sub-step to your Workflow, and this action will take place 7 days (one week) before the date specified in that attribute.  The next thing you'll want to do is configure a set of rules that handles whether or not the stored date changes, and to send the expiration notice if it doesn't.  That can be tricky, because there isn't a very nice way of determining whether an attribute has changed in the middle of a Workflow's execution.  You can use the Workflow trigger and a parallel wait condition to give you what you want.

    After the email action, configure a new Wait Condition similar to the first, but without the "7 days before" modification in step 6.  Then, configure a parallel wait condition to this, with the following settings:

    1. Select your custom entity from the entity picklist
    2. Select the expiration attribute from the attribute picklist
    3. Select "Is Greater Than" from the operator picklist
    4. In the Dynamic Values box, specify 7 "Days" and "After", and then select Workflow from the "Look For" field, and pick Execution Time .
    5. Save and Close the condition page

    As a sub-step to this parallel condition, add a "Stop Workflow" action, and set the status to "Canceled".  You can then add your expiration notice email as a sub-step of the second Timeout step.  What this will do is wait for one of two things to occur: either the expiration date is met, and your email about the expiration is sent.  Or the expiration date is extended more than 7 days beyond the current execution time of the Workflow; which means that the expiration date has been advanced significantly, and therefore requires an entirely new instance of this Workflow to provide a 1-week warning.

    Then, configure the Workflow's triggers to "Start when" the "Record is created", and when "Record attributes change" and be sure to select the expiration date attribute.  Then, if ever the expiration date changes after the initial warning is issued, your customer will be able to receive another 7-day warning.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Saturday, September 18, 2010 12:10 AM
    Moderator

All replies

  • Hi

    You need a recursive workflow to achieve this task please follow the link this gives you an insight in to designing such a workflow.

    http://www.dynamicscrmtrickbag.com/2010/06/02/recursive-workflows/

    https://community.dynamics.com/blogs/crmayazahmad/comments/46092.aspx

    PS: because the workflows are long waiting in such scenario's it is very resource intensive.


    Hope this helps. Amar
    Monday, August 30, 2010 7:03 PM
  • I'm not sure you need a recursive workflow but you will need to have a workflow with a wait condition.

    Leon Tribe

    Want to hear me talk about all things CRM? Check out my blog

    http://leontribe.blogspot.com/ 
    or hear me tweet @leontribe


    Want to hear me talk about all things CRM? Check out my blog http://leontribe.blogspot.com/ or hear me tweet @leontribe
    • Proposed as answer by Leon TribeMVP Tuesday, August 31, 2010 6:47 AM
    Tuesday, August 31, 2010 6:47 AM
  • An Example would me more helpful. particularly for custom entities  date/time based events. 
    Tuesday, August 31, 2010 6:44 PM
  • Hi Leon,

            how can i check the wait condition 

    for example

     

    i have one expiry date field on entity and on template

    i write the condition some thing like this,

    <EntityName> <ColumnName/FieldName> <On Or After> <DateTimeValue>

     

    in this sample i want to refer <DateTimeValue> as entered while creating record in CRM Entity  ie Expiry Column field.

    and i want to check this <DateTimeValue> against the system date. and if the system date time is greater than  <DateTimeValue> then trigger an email.

    How could i achieve this?

    Friday, September 17, 2010 11:19 PM
  • Hi

    You need a custom workflow activity to get the current date...please check this post for the same

    http://a33ik.blogspot.com/2009/11/custom-workflow-action-which-returns.html

     

    Once you have registered this custom workflow activity using plugin registration tool you can then create the wait condition between the Expiry Column and the value returned from the custom workflow

     


    Hope this helps. Amar
    Friday, September 17, 2010 11:40 PM
  • Workflows can "timeout until" a particular date, and the condition operators would allow you to use this to specify any duration before or after a date stored in CRM.  You can provision your workflow with two "timeout" conditions, one for a week before the stored date, and the other for the date itself.  To do this:

    1. Click on Add Step and select "Wait condition".
    2. Click on the condition to configure it.
    3. Select "Workflow" from the entity picklist.
    4. Select "Timeout" from the attribute picklist.
    5. Select "Equals" from the operator picklist.
    6. In the Dynamic Values box, specify 7 "Days" and "Before", and then select the attribute that contains your stored date.
    7. Save and Close the condition page.

    You may now add an email action as a sub-step to your Workflow, and this action will take place 7 days (one week) before the date specified in that attribute.  The next thing you'll want to do is configure a set of rules that handles whether or not the stored date changes, and to send the expiration notice if it doesn't.  That can be tricky, because there isn't a very nice way of determining whether an attribute has changed in the middle of a Workflow's execution.  You can use the Workflow trigger and a parallel wait condition to give you what you want.

    After the email action, configure a new Wait Condition similar to the first, but without the "7 days before" modification in step 6.  Then, configure a parallel wait condition to this, with the following settings:

    1. Select your custom entity from the entity picklist
    2. Select the expiration attribute from the attribute picklist
    3. Select "Is Greater Than" from the operator picklist
    4. In the Dynamic Values box, specify 7 "Days" and "After", and then select Workflow from the "Look For" field, and pick Execution Time .
    5. Save and Close the condition page

    As a sub-step to this parallel condition, add a "Stop Workflow" action, and set the status to "Canceled".  You can then add your expiration notice email as a sub-step of the second Timeout step.  What this will do is wait for one of two things to occur: either the expiration date is met, and your email about the expiration is sent.  Or the expiration date is extended more than 7 days beyond the current execution time of the Workflow; which means that the expiration date has been advanced significantly, and therefore requires an entirely new instance of this Workflow to provide a 1-week warning.

    Then, configure the Workflow's triggers to "Start when" the "Record is created", and when "Record attributes change" and be sure to select the expiration date attribute.  Then, if ever the expiration date changes after the initial warning is issued, your customer will be able to receive another 7-day warning.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Saturday, September 18, 2010 12:10 AM
    Moderator
  • Brilliant!!
    Thursday, October 28, 2010 7:57 PM
  • This is a very good option.

    I do have 1 issue with it.

    If i create a new entity, say with expire data 4/29/2011.
    After saving i realise it should have been  4/30/2011.

    On 4/23/2011 (7 days before) i will receive 2 emails. Both identical.

    How can i prevent that 2 mails are sent. 

    Wednesday, March 23, 2011 3:34 PM
  • Yes, this particular solution is tailor-made to address the very specific nature of the issue presented:  namely, that expiration date advancement occurs after the original notice is sent.  Unfortunately, it doesn't work for many other situations, as you point out, nsijtsma.  In that case, there would need to be a very clear indication of the "cause" of expiration date advancement, specifically whether or not it's related to the the conclusion of the principal Timeout condition.  Obviously, if that Timeout hasn't been met, it's a pretty good indicator... however, the secondary Workflow will be unable to ascertain that.

    Therefore, it stands to reason that in order to resolve your quandary, nsijtsma, one Workflow must understand the progress of another.  This could be accomplished by customized code, but a far simpler method involves an a simple "bit" attribute on the expiring record.  Imagine that before our Timeout, we performed two additional steps:

    1. Check the value of this "bit" field.  If "true", then stop the Workflow execution
    2. Set the value of the "bit" field to "true"

    Then, all we would need to do is change the value to "false" immediately after the email expiration notice is sent, clearing the way for our original process to remain in place.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com Please follow the forum guidelines when inquiring of the dedicated CRM community for assistance.
    Wednesday, March 23, 2011 5:42 PM
    Moderator