1

I have a complicated sequential SP2010 workflow with various paths, loops, different custom forms for submitting/editing/approving tasks, etc. Tasks are set up with the typical - createTask -> While Loop -> onTaskChanged -> completeTask -> deleteTask activity pattern.

Everything has seemed to work out pretty well, with minor issues, but this has me stumped. Basically, if I kick off two workflows and get them onto the same approval step, with the same type task pending, and approve one of the tasks, BOTH workflows pick up the change and complete!

When I debug, I can see from my codebehind that I am calling AlterTask on the task item from one workflow (lets say Inspector approval task for PO#111), and immediately following that, the 'onTaskChanged' event from the OTHER workflow (lets say PO#222) gets hit, followed by the 'onTaskchanged' from THIS workflow (PO#111). The afterproperties from both of these events contain the data from the single alterTask call. Both workflows then continue on, and I am left with two workflow instances, both complete, but one still has an outstanding task and no input from that task.

I'm not really sure what to do. I would assume SharePoint manages the task's relationship to their workflow instances, and I can't work out how the wires are getting crossed here.

1

This is the workaround I've implemented. I would love more information for the root cause of this, but I just need to get it working and don't have time for SharePoint quirks...

private bool isValidEvent(Hashtable extendedProperties)
    {
        if(extendedProperties.ContainsKey("wfInstanceID"))
        {
            Guid taskWfInstanceID = new Guid(extendedProperties["wfInstanceID"].ToString());
            return taskWfInstanceID.Equals(workflowProperties.WorkflowId);
        }
        else
        {
            return false;
        }
    }

I send the workflow instance ID from the form to the workflow via AlterTask then I check to make sure the workflow instance ID that I get from the form matches this workflow's instance ID. If it doesn't, we just return out of the onTaskChanged event. This works nicely, though it shouldn't be necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.