Question

I'm trying to create a workflow on the Sharepoint Designer. The workflow should wait until an Out-Of-The-Box approval workflow is complete. This is done by starting my workflow with the item's creation, and usign the wait activity:

Wait for field change in current item:
Wait for InternalApproval to equal 16

The problem: the rule is correct, but the event doesn't fire unless an edit is made on the item. Normally, every edit triggers the workflow check, but my tests show approving a workflow doesn't trigger this event on the item.

Is there an easy way around this issue? I though about implementing a busy wait, but how (there's a wait 5 minutes activity, but no goto)? Is there an activity I can download that can wait for another workflow to complete, or busy wait until a condition is met?
Another way to solve my problem is if the InternalApproval workflow changed a field, but I cannot achieve that either...

Was it helpful?

Solution 2

I ended up writing a custom workflow activity that waits until a change is made, and resumes the workflow. This activity can be used in two ways - on the main workflow, or on a second workflow, where it waits for a non-triggering change, and makes a triggering change (so the main workflow resumes).
Writing it was big fun - I used Reflector to copy some code from an OOTB activity (the normal Wait For Field Change), and copied its action xml. This works very well after some tries, giving a list of fields, operators and values.

Custom Sharepoint Workflow Activity - I

Checking the condition is also quite simple, using the Helper class. All properties and their binding were copied using Reflector:

public void CheckStopCondition(object sender, ConditionalEventArgs e)
{
    bool checkAgainLater = Helper.TestListItem(Context, ListId, ListItem, 
                                               FieldName, Operator, Value);
    e.Result = checkAgainLater;
}

OTHER TIPS

This is expected behaviour. An approval workflow that is wired to cancel itself upon changes to the item would otherwise be useless. At the API level, SharePoint is disabling events from being raised when it needs to update the item upon which it is running.

-Oisin

The article How to wait for a change in any list, wait for multiple field changes the current item for a different take on waiting for field changes in the current item (link below).

The article explains how to configure a workflow which uses Standard (OOB) workflow actions and is developed using SharePoint Designer. Instead of using the "Wait for field change in the current item" action, the components of the workflow which are completed after waiting is finished are added to a separate "On Change" workflow, which uses standard conditions in the first step to determine if it can continue. If the conditions are not met for the field in the current item, the workflow will stop. If another instance of the workflow is running, new instances will also stop by setting a "Workflow_running" field to yes while an instance is running.

Using this technique gives you more control when waiting for specific criteria to be met. This includes being able to wait until a field in another list item is updated, or waiting for multiple fields in the current item.

See How to wait for a change in any list, wait for multiple field changes the current item (SharePoint Workflow) for more details.

When using one workflow for approval and another workflow for updating a field, you can use "Wait for field change in current item", to update field when the approval is made (either approved code 16, rejected code 17, In progress code 2) here is an example:

Wait for MomoApproval to equal 16 then set Notification to Final

This code will not fire when the approval is made because SharePoint modifies a field that is related to the workflow; this field does not belong to the schema of the list. Therefore, change on the workflow status does not trigger an item change event. Without an item change event the second workflow will remain idle and the "Wait for field change in current item" action will seem useless, to bypass this behaviour of SharePoint 2010 Approval workflow, do the following:

  1. Open SharePoint designer 2010
  2. Go to the site you are working on
  3. Click on workflows
  4. Right click on Approval workflow
  5. Click copy and modify
  6. Go to the concerned list
  7. Click associate existing workflow
  8. Now within this workflow, click edit workflow, click Approval workflow task
  9. Click change the behaviour of the single Task
  10. Go to the complete section and add this action "set Title to Current Item: Title"

This will change the title field within the schema of the list which will trigger an item change event but the value of the title is going to remain the same, this action will have no effect on data content of the list. This is simple workaround that work fine and that will cost less in comparison to other solutions such as creating an activity, looping, or pausing and restarting workflows

Once created the workflow can be imported to visual studio 2010 and be part of the solution please refer to this link : http://msdn.microsoft.com/en-us/library/ee231580.aspx

Enjoy your workflow updates

Note: The workflow that is updating the field should be bound to start when there is an item change within the list.

Mohamed Hachem

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top