Avoid issue of running multiple background workflow processes

Requirement

Whenever user sets due date on task record, a reminder should go to owner of the task.

Implementation Approach: We will implement this using a workflow with below configuration:

  1. Create a background workflow on task entity.
  2. Set trigger points of workflow as below:
    1. When record is created.
    2. When task due date is updated.
  3. Set workflow logic as below:
    1. Wait until Due Date becomes true (i.e. wait until due date arrives).
    2. On success, send email notification.

Note: In this blog, I have not focused on how workflow is created and how above steps are achieved.

Problem Statement

Above approach will not work properly in below scenario:

  1. User creates task and sets due date as 5 days later.
    1. A background process will be created and will go in wait condition.
  2. User again opens the task created above and updates the due date as 7 days later.
    1. In this case as well, new background process will be created and will go in wait condition.

Now, when actual due date arrives i.e. 7 days after, both of the background processes will be succeeded and 2 email notifications will be sent to the owner. This is incorrect and needs to be fixed.

Solution

To solve this issue, I have created a custom workflow assembly which checks active background process count associated with the record and returns the value back in output parameter. So, if we call this custom workflow as a first step in our workflow and if active session count is equals to 0, then we can proceed else we will stop workflow.

This way, at any given point of time, there will be only 1 active session which will be succeeded on actual wait condition success.

I have attached managed solution which contains below 2 components:

  1. Custom Workflow Assembly.
  2. A sample workflow on task entity (in deactivated state) to show an example and how to use it.

Download managed solution here.

How it works

how-it-works

Advertisements

2 thoughts on “Avoid issue of running multiple background workflow processes

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