Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Approve Workflow Task Programatically

$
0
0

Overview:
I am trying to approve a task programatically using either SharePoint Web Services or Client Object Model. I can update the task properties but the workflow doens't move to the next step.

Details:
I have created a list and associated a simple SharePoint 2010 approval workflow with it. The workflow is simple, just approve the task from 2 users one at a time.
When I create an item in the list and start the workflow, a task is created and I can approve it manually. After it is approved by the first user, it goes to the second one. After being approved by the second user, the workflow is completed.
Programatically, I can access the task and change some of its properties but the workflow never moves to the next step.

Using Web Services:
I am calling UpdateListItems method of Lists.asmx

batchElement.InnerXml = "<Method ID='1' Cmd='Update'>" // Also tried Cmd='Moderate' but I believe it is giving the same result                + "<Field Name='ID'>115</Field>"                + "<Field Name='Status'>Completed</Field>"                + "<Field Name='FormData'>Completed</Field>"                + "<Field Name='WorkflowOutcome'>Approved</Field>"                + "<Field Name='Completed'>True</Field>"                + "<Field Name='PercentComplete'>1</Field>"                + "<Field Name='_ModerationStatus'>0</Field>"
        //+ "<Field Name='ws_TaskStatus'>Approved</Field>" // This result in an error (column is not defined)                + "</Method>"; 
XmlNode response = listProxy.UpdateListItems(listID, batchElement);
Console.WriteLine(response.InnerText);

 

Using Client Object Model:

cxt.Load(item);

item["Status"] = "Completed";
item["Completed"] = true;
item["PercentComplete"] = 1;
item["WorkflowOutcome"] = "Approved";
item["FormData"] = "Approved";
item["_ModerationStatus"] = "0";
item.Update();

cxt.ExecuteQuery();

 

The result for both methods is that the task list item is updated but the workflow doesn't move forward.

I have read some workarounds, below, but none of them are working:
1- WorkflowOutput is  readonly and you have to update FormData instead
2- Using Moderate in web services instead of update
3- Update a field called ows_TaskStatus or ws_TaskStatus.

I have noticed that there is a difference between the ExtendedProperties of an item that has been approved manually and the one that was updated programatically. For the item that has been approved manually the extended properties show, among other items, ws_TaskStatus='Approved' however in the items used programatically this property is missed.

Can someone show me how to approve a task item programatically using any method?

Best regards,
Shehab.


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>