Thursday, April 26, 2007

Updating an Item from a workflow monitoring the OnItemChanged event.

Scenario: Workflow is waiting on the OnItemChanged event of a SP list. We need to update the same item from the workflow.

Solution:
Do not use the Update method of SPListItem. This will surely make the workflow go into recursion.

Instead add a CallExternalMethod Activity.
Select the interface type as IListItemService
Method : UpdateListItem

Bind the following properties:
1. ListId : Bind to the workflowproperties.ListID
2. ItemId : Bind to the workflowproperties.ItemID
3. Id. : To a new GUID
4. itemProperties: This is an important property. This property holds the ColumnName,Value pair that needs to be updated.

Once you bind the itemProperties to a field, you can add columns and the their values like any other ArrayList/Dictionary.

Once this activity executes the list item gets updated.

NOTE: This solution does sometime make the workflow go into recursion. But this recursive behaviour is not consistent.

No comments: