1

When I approve a Task using JSOM code it doesn't triggers "When Task is Completed" step in approval workflow. But when I approve it through OOB InfoPath form, it does triggers and send the mails as expected.

Below is the code that I used to approve a task:

var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var tasksList = web.get_lists().getByTitle("Tasks");
var task = tasksList.getItemById(itemId);

task.set_item("Status", "Completed");
task.set_item("Completed","TRUE");
task.set_item("PercentComplete", 1);    
task.set_item("WorkflowOutcome",outcome);

task.update();

I verified the Task attributes after execution of above code. All of them are getting updated as expected.

My question is, do I need to update some any other fields of Task to trigger it or it's not at all possible through custom code?

Any help will be much appreciated.

0

After lot of trial and hits, I got to know that, It's not possible with REST or JSOM. You need to set TasskStatus to Completed which we can not set using REST. It is Possible using Server Side Code:

Hashtable hashTable = new Hashtable();
hashTable["Status"] = "Complete";
hashTable["PercentComplete"] = 1.0f;
hashTable["TaskStatus"] = "#";//#- Approved and @- Rejected

SPWorkflowTask.AlterTask((taskedit as SPListItem), hashTable, true);

Post execution of this code, it will resume WF and enters the Completed state.

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.