locked
Running workflows on a particular date RRS feed

  • Question

  • I want all workflows on all my contracts to run every Monday.
    How do I ensure that regardless of when they were triggered, they will always run on every monday ?*(or for that matter any day with a 7 day interval in between)
    Wednesday, May 30, 2012 12:00 PM

Answers

  • Hang with me here, this is going to sound complicated but if you think about it, it's not that bad if you really need this exact functionality :) I have not done this exactly but have done some similar things that suggest the following possible approach.

    1. Create a custom entity 'workflow queue' with attributes to store the workflow id, the record id you want to run the workflow against, and any other data you might need (such as a 'type' in case you want to have different types fire at different dates/times)

    2. Create a new workflow that, instead of firing the 'real' workflow, simply inserts the appropriate data into the 'workflow queue'. Use that from all locations that need to 'trigger' a record to be added to the queue. (don't forget to decide what you need to do to handle duplicates - for example, if a user modifies the contract multiple times before the next execution window) You may need a custom workflow activity for this (I don't think all the information you need to set is exposed by the out-of-box workflow selections), but it shouldn't be complex.

    3. Offload the whole scheduling problem by creating a windows service, or a .NET exe that runs as a scheduled task, that 'fires' during your desired execution window(s), retrieves the queue entries relevant to the current execution window, and immediately invokes the selected queued workflows against the stored record id's. Then the async service will process them all as normal.

    • Marked as answer by boo oinky Thursday, May 31, 2012 7:15 AM
    Wednesday, May 30, 2012 4:12 PM

All replies

  • You will need something like http://manipulationlibrary.codeplex.com/ to get only business days. Or you should take a look at http://gonzaloruizcrm.blogspot.de/2011/05/quite-often-we-have-business-process.html. This could be another way of recurrence.

    Carsten Groth http://carstengroth.wordpress.com Microsoft Dynamics Certified Technology Specialist

    Wednesday, May 30, 2012 12:18 PM
  • The only way I can think of doing this would be to make your workflow available as a child and have it call itself with a timeout of 7 days in it.

    Leon Tribe

    Want to hear me talk about all things CRM? Check out my bloghttp://leontribe.blogspot.com/ 
    or hear me tweet http://www.twitter.com/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 Wednesday, May 30, 2012 1:40 PM
    Wednesday, May 30, 2012 1:40 PM
  • Hi Leon,

    Thanks for your reply. My requirement is that regardless of when the workflow is triggered, it should run through on a particular day at a specific interval (e.g. if it is triggered on a Tuesday, then the workflow should follow through on the following Monday. Even if it is triggered on a Thursday, it should still run through on the nearest following Monday) Any suggestion ?

    Wednesday, May 30, 2012 3:36 PM
  • Hang with me here, this is going to sound complicated but if you think about it, it's not that bad if you really need this exact functionality :) I have not done this exactly but have done some similar things that suggest the following possible approach.

    1. Create a custom entity 'workflow queue' with attributes to store the workflow id, the record id you want to run the workflow against, and any other data you might need (such as a 'type' in case you want to have different types fire at different dates/times)

    2. Create a new workflow that, instead of firing the 'real' workflow, simply inserts the appropriate data into the 'workflow queue'. Use that from all locations that need to 'trigger' a record to be added to the queue. (don't forget to decide what you need to do to handle duplicates - for example, if a user modifies the contract multiple times before the next execution window) You may need a custom workflow activity for this (I don't think all the information you need to set is exposed by the out-of-box workflow selections), but it shouldn't be complex.

    3. Offload the whole scheduling problem by creating a windows service, or a .NET exe that runs as a scheduled task, that 'fires' during your desired execution window(s), retrieves the queue entries relevant to the current execution window, and immediately invokes the selected queued workflows against the stored record id's. Then the async service will process them all as normal.

    • Marked as answer by boo oinky Thursday, May 31, 2012 7:15 AM
    Wednesday, May 30, 2012 4:12 PM