Welcome to MSDN Blogs Sign in | Join | Help

Sending a reminder in a sequential workflow

A common task in a workflow is to send a reminder email to a user, if he/she does not complete the task within a timeframe (e.g. one day). One way to implement this functionality in a Sequential Workflow is to leverage EventHandlingScope and Delay activities by following these steps:

  1. After CreateTask activity add an EventHandlingScopeActivity and put a WhileActivity along with an OnTaskChanged and UpdateTask as child activities and set the correlation token and other properties.

  2. In designer Switch to EventHandlingScope's EventHandler view, add an EventDrivenActivity and a DelayActivity and a CodeActivity as child activities.

  3. Use SPUtility.SendEmail inside the CodeActivity to send a reminder email to requestor's address.

 

Update (Here is a different approach for sending regular reminders using ConditionedActivityGroup (CAG), submitted by my colleague Daniel Odievich):

When developing SharePoint workflows, one often needs to send email notification for a task, and then keep sending regular reminders for this task at scheduled intervals. When developing workflows in SharePoint Designer, one can use DelayUntilActivity and DelayForActivity, but those were not designed for in Visual Studio workflows.

One solution already presented by Ali (http://blogs.msdn.com/alimaz/archive/2008/01/22/sending-a-reminder-in-a-sequential-workflow.aspx) is to use EventHandlingScopeActivity to wait for the task notification while using its contained EventDrivenActivity to queue up a delay using DelayActivity. Unfortunately, this approach limits you to one-time reminder as DelayActivity will only execute once, instead of regular reminders. If you try to wrap DelayActivity in a WhileActivity, the EventDrivenActivity won’t compile because its first child must be IEventActivity (such as DelayActivity).

A different solution is to use the ConditionedActivityGroupActivity (http://msdn.microsoft.com/en-us/library/bb675237.aspx) with OnTaskChanged in one group, DelayActivity in another group and a couple of code conditions to loop around them.

The pseudo-code structure of this design is:

<CreateTask />

<SendEmail Type=“First” />

<ConditionedActivityGroup UntilCondition=“Until_TaskComplete_Condition” >

<SequenceActivity Type=“Task” WhenCondition=“While_TaskNotComplete_Condition”>

<OnTaskChanged />

<UpdateTask />

</SequenceActivity>

<SequenceActivity Type=“Reminder” WhenCondition=“While_TaskNotComplete_Condition”>

<DelayActivity />

<SendEmail Type=“Reminder” />

</SequenceActivity>

</ConditionedActivityGroup>

<CompleteTask />

As long as the task is not done, Until_TaskComplete_Condition should be setting its e.Result to “false”. Meanwhile, While_TaskNotComplete_Condition should be setting its e.Result to “true”. Once the task is complete, Until_TaskComplete_Condition should be setting its e.Result to “true”, while While_TaskNotComplete_Condition should be setting its e.Result to “false”. In other words, the outcomes of these evaluations should be opposite values (Until_TaskComplete_Condition != While_TaskNotComplete_Condition).

When task is created, the following sequence of events will occur:

1. <CreateTask />

2. <SendEmail Type=“First” />

3. <ConditionedActivityGroup UntilCondition=“Until_TaskComplete_Condition” >

4. <SequenceActivity Type=“Task” WhenCondition=“While_TaskNotComplete_Condition”>

5. <OnTaskChanged /> - register

6. <SequenceActivity Type=“Reminder” WhenCondition=“While_TaskNotComplete_Condition”>

7. <DelayActivity /> - sleep

The workflow will then go to sleep and wait for OnTaskChanged event or for DelayActivity to elapse.

If OnTaskChanged event wakes up workflow, and task has not been completed, the OnTaskChanged group of activities will run to complete and be scheduled again because Until_TaskComplete_Condition will not evaluate to “false”. DelayActivity group of activities will still be waiting for delay to elapse. Following sequence of events will occur:

1. <OnTaskChanged /> - wake

2. <UpdateTask />

3. <ConditionedActivityGroup UntilCondition=“Until_TaskComplete_Condition” > - true

4. <SequenceActivity Type=“Task” WhenCondition=“While_TaskNotComplete_Condition”>

If OnTaskChanged event wakes up workflow, and task has been completed, the OnTaskChanged group of activities will run to completion. Because Until_TaskComplete_Condition will evaluate to “true”, the ConditionedActivityGroup will consider itself done, cancel execution DelayActivity group of activities and move to next step in workflow. Following sequence of events will occur:

1. <OnTaskChanged /> - wake

2. <UpdateTask />

3. <ConditionedActivityGroup UntilCondition=“Until_TaskComplete_Condition” > - false

4. <CompleteTask />

When DelayActivity elapse before the task is completed, the DelayActivity group of activities will run to completion and be scheduled again because Until_TaskComplete_Condition will not evaluate to “false”. The OnTaskChanged group of activities will still be waiting for Task Changed event. Following sequence of events will occur:

1. <DelayActivity /> - wake

2. <SendEmail Type=“Reminder” />

3. <ConditionedActivityGroup UntilCondition=“Until_TaskComplete_Condition” > - true

4. <SequenceActivity Type=“Reminder” WhenCondition=“While_TaskNotComplete_Condition”>

5. <DelayActivity /> - sleep

The workflow designer outline of this is shown below:

clip_image002

The OnTaskChanged branch of CAG

clip_image004

DelayActivity branch of CAG

Published Tuesday, January 22, 2008 4:27 AM by AMazaheri

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Using Delay activity in WSS 3.0 custom Workflows (Lessons learned)

WF&#39;s DelayActivity is best suited for scenarios such as sending Reminders or if you want to force

Friday, February 08, 2008 12:00 AM by Noticias externas

# re: Sending a reminder in a sequential workflow

could you post your code here?

Thursday, March 13, 2008 11:10 PM by basquang

# re: Sending a reminder in a sequential workflow

I am building custom approval workflow, my problem is how do I  reassign a task to another approver if one of the approvers the multiple approvers is on vacation. I know i have to implement add eventhandlingscope, enableworkflowmodification but not sure exactly how.

Any help will be appreciated.

Thursday, March 27, 2008 11:53 AM by ms

# re: Sending a reminder in a sequential workflow

You can either assign the task to a SharePoint Group (e.g. Approvers)and let a member of a group Claim the task, or use Workflow Modification. You can find a sample on ECM starter kit.

Friday, March 28, 2008 6:02 PM by AMazaheri

# re: Sending a reminder in a sequential workflow

basquang,

A Whitepaper will be published on MSDN which includes the code for this feature, I'll post it here when its published.

Sunday, March 30, 2008 4:51 PM by AMazaheri

# Sending an email notification every monday

Hi,

I have a requirement where i will have to send an email reminder every monday morning at 8 am when an item is added to a document library to modify the file is not modified we have to send the alert again on monday morning. Can you tell me how to get along with this kind of scenario.

Thanks in advance

Tuesday, August 26, 2008 9:10 AM by Paddy

# re: Sending a reminder in a sequential workflow

can you please send the code for that application...

Friday, October 17, 2008 2:45 AM by sam

# re: Sending a reminder in a sequential workflow

Hi,

I have used a replicator activity(to creat emultiple tasks)in one leg of the CAG and a delayactivity in other leg. In this case the delayactivity is not getting invoked after the timeout duration. It gets invoked only when one o fthe task created by the replicator is completed.

Thanks.

Friday, January 02, 2009 3:10 AM by Remya

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker