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.

1
  • 1
    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 Commented Sep 14, 2019 at 16:54

3 Answers 3

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());
});
1
  • Workflow task is getting approved, but the Nintex workflow's flexi task is not getting proceeded in the 'Approve' branch. Commented Nov 28, 2020 at 8:55
1
var siteURL = "https://xxxxxxxxxxxxxxxxxxxx"; //Your site URL here
var varComments = 'Task approved from test'; //Approver comments
var varOutcome = 'Approve'; //Workflow flexi task outcome
var varTaskListName = 'Workflow Tasks'; //Workflow Tasks list name
var varTaskId = 44;    //Workflow task item ID
  
var webSvc = siteURL + "/_vti_bin/NintexWorkflow/Workflow.asmx";
var rqst = '<?xml version="1.0" encoding="utf-8"?>';
rqst += '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:m="http://nintex.com">'; 
rqst += '<soap:Header>';
rqst += '</soap:Header>';
rqst += '<soap:Body>';
rqst += '<m:ProcessFlexiTaskResponse2>';
rqst += '<m:comments>'+varComments+'</m:comments>';
rqst += '<m:outcome>'+varOutcome+'</m:outcome>';
rqst += '<m:spTaskId>'+varTaskId+'</m:spTaskId>'; 
rqst += '<m:taskListName>'+varTaskListName+'</m:taskListName>';
rqst += '</m:ProcessFlexiTaskResponse2>';
rqst += '</soap:Body>'; 
rqst += '</soap:Envelope>';
$.ajax({
    type: "POST",
    url: webSvc, 
    contentType: "text/xml;charset=UTF-8",
    data: rqst,
    dataType: "xml", 
    success: function(data,status,xhr) {console.log('OK: ' + status);},
    error: function (data) {console.log(data.responseText);}
});

enter image description here

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 and acknowledge you have read our privacy policy.

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