4

I am trying to find out the right way to approve a listitem workflow task clicking on a button using JavaScript (client object model). An approver should be able to approve/reject his own task by clicking on a link or a button associated with the current item.

  • var item = list.getItemById(dataTaskId); item.set_item('Completed', true); item.set_item('PercentComplete', 1); item.set_item('Status', "Approved"); item.set_item('WorkflowOutcome', "Approve"); tried updating Nintex outcome column "WorkflowOutcome" with both Approve/ Approved. Task list is updated correctly. But my Nintex workflow did not move forward. It is not able to switch to Approve or Reject branch. Please advice – Pradeep Kini Sep 14 '19 at 16:54
4

How to approve workflow task item using JSOM

The following example demonstrates how to approve task item using JSOM

function approveTask(listTitle,itemId, success,error){
    var ctx = SP.ClientContext.get_current();
    var list = ctx.get_web().get_lists().getByTitle(listTitle);
    var item = list.getItemById(itemId);
    item.set_item('Completed',true);
    item.set_item('PercentComplete',1);
    item.set_item('Status','Approved');
    item.set_item('WorkflowOutcome','Approved');
    item.update();
    ctx.executeQueryAsync(
      function() {
          success();
      },
      error
    );
}

Example

approveTask('Workflow Tasks',1,function(){
    console.log('Task has been approved');
},
function(sender,args){
    console.log(args.get_message());
});
0

Using JSOM you can update any list item.

In particular to approve a task item, you should update following fields

taskItem["WorkflowOutcome"] = "Approved";
taskItem["FormData"] = "Completed";
taskItem["Status"] = "Approved";
taskItem["PercentComplete"] = 1;
taskItem["Completed"] = true;

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.