Multiple OnWorkflowItemChanged activities fail on SharePoint Server

Article ID: 2694420 - View products that this article applies to.
Expand all | Collapse all

SYMPTOMS

Consider the following scenario:

You have a workflow (state machine) solution running on SharePoint Server 2010 that contains multiple ‘OnWorkflowItemChanged’ activities.
After the workflow initializes, when an item changed event is triggered, either through the UI or the Object Model (OM), the OnWorkflowItemChanged event is triggered multiple times.

CAUSE

When the OnWorkflowActivated event fires, SharePoint delivers one event for each OnWorkflowItemChanged activity inside the state machine workflow. For example, if there are 3 OnWorkflowItemChanged activites inside the state machine workflow, then there will be 3 subscriptions for the workflow. So when an item changed event occurs, all 3 subscriptions are triggered.

This is expected behavior at the time of creation of this article. You can follow the workaround listed below to resolve this issue.

RESOLUTION

Workflow Design View:

Collapse this imageExpand this image
2696576


Workaround:

Step 1: Initialize a subscription for ItemChanged event(StateOne)

1.       Drop a CallExternalMethodActivity within  the stateInitializationActivity1 activity
2.       Set a new CorrelationToken(StateOneToken) and the OwnerActivity(StateOne)
3.       Bind the id  property to a new field/property, named it as ‘subscriptionID’
4.       Select the InterfaceType as Microsoft.SharePoint.Workflow.IListItemService
5.       Bind the property itemId to workflowPropeties.ItemId
6.       Bind the property listId to workflowProperties.ListId
7.       Set the MethodType as InitializeForEvent          


Collapse this imageExpand this image
2696577



Step 2: Replace all OnWorkflowItemChanged activities with HandleExternalEventActivity(StateOne)

1. Set the same Correlation(StateOneToken) token set for the CallExternalMethodActivity
2.Select the InterfaceType as Microsoft.SharePoint.Workflow.IListItemService
3.Select the EventName as OnItemChanged
4. For handling the OnItemChanged event, a function can associated to the event Invoked

Collapse this imageExpand this image
2696579




Step 3: Initialize a subscription for ItemChanged event(StateTwo)

1.       Drop a CallExternalMethodActivity within  the stateInitializationActivity2 activity
2.       Set a new CorrelationToken(StateOneToken) and the OwnerActivity(StateOne)
3.       Bind the id  property to a new field/property, named it as ‘subscriptionID’
4.       Select the InterfaceType as Microsoft.SharePoint.Workflow.IListItemService
5.       Bind the property itemId to workflowPropeties.ItemId
6.       Bind the property listId to workflowProperties.ListId
7.       Set the MethodType as InitializeForEvent          

Collapse this imageExpand this image
2696580



Step 4: Replace all OnWorkflowItemChanged activities with HandleExternalEventActivity(StateTwo)

1. Set the same Correlation(StateTwoToken) token set for the CallExternalMethodActivity
2. Select the InterfaceType as Microsoft.SharePoint.Workflow.IListItemService
3.Select the EventName as OnItemChanged
4.For handling the OnItemChanged event, a function can associated to the event Invoked

Collapse this imageExpand this image
2696581



Step 5: Assign the Subscription Id with the document GUID

Once you have initialized for subscribing list events, you now need to assign the subscriptionID (the property bound to id) with the document GUID. This can be done within the OnWorkflowActiviated event handler.

Collapse this imageExpand this image
2696582


Note: The steps (1 & 2 or 3 & 4) should be performed for all the CallExternalMethodActivityHandleExternalEventActivities within you state machine workflow.

MORE INFORMATION

There has been a similar issue noted in some cases while using multiple OnWorkflowItemChanged activities in complex sequential workflows mixed with onTaskChanged events. The solution is to create a manual event subscription as modeled in this article.
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use for other considerations.

Properties

Article ID: 2694420 - Last Review: May 3, 2012 - Revision: 3.0
APPLIES TO
  • Microsoft SharePoint Foundation 2010
  • Microsoft SharePoint Server 2010
Keywords: 
KB2694420

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com