AnsweredAssumed Answered

Start Nintex workflow in javascript

Question asked by jasonleung on Jan 17, 2016
Latest reply on Jan 18, 2016 by vadim.tabakman@nintex.com

Hi all,

 

Background Info:

Our Nintex Form requires a "Create COPY" function that makes a copy of an existing list item, and adds to the same list.
I have this copy logic working the way we need it to in a Nintex Workflow using the COPY ITEM workflow control.

 

This "Create a copy" feature is only available on completed forms via Display (view) mode.

 

As such, I added a Javascript Button (instead of a SAVE or SUBMIT button - as once the form is completed, the users will only have READ access to the form). So a SAVE or SUBMIT button won't work as SP won't allow saving via Display mode.

 

The Problem:

My solution below works 100% if the user is a system admin.

 

POINT 1:  Setting the AUTH header in the AJAX call by executing the line:

       //xhr.setRequestHeader ("Authorization", "Basic " + window.btoa("login:pass"));

       // where login/pass is a system admin account

 

Uncommenting the above live does not work for users that have "Contribute" permissions on the site. The error is 500 - Internal  server error.

 

POINT 2:  Setting the Username and Password parameters in the AJAX call:

   // username: "login",

   // password: "pass",

   // where login/pass is a system admin account

 

Uncommenting the above lines work, but it seems that after the AJAX call executes, the Logged in user for Sharepoint is now the accounts defined by (login/pass)

ie the system admin account. Which is very weird.  The user needs to logout and close the browser window for Sharepoint to recognise the actual users account again.

 

 

Current solution (partially not working):

When the JS button is clicked, an AJAX call is made to the Web Service method "StartWorkflowOnListItem" using the serice @ "_vti_bin/NintexWorkflow/Workflow.asmx"

 

Here's the JS code:

 

Header 1

function StartCreateCopyWF(ItemID, ListName, SiteURL, WFName) {

 

 

var sr = '<?xml version="1.0" encoding="utf-8"?>'

    + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '

    + 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" '

    + 'xmlns:m="http://nintex.com">'

    + '<soap:Header>'

    + '</soap:Header>'

    + '<soap:Body>'

    + '<m:StartWorkflowOnListItem>'

    + '<m:itemId>' + ItemID + '</m:itemId>'

    + '<m:listName>' + ListName + '</m:listName>'

    + '<m:workflowName>' + WFName + '</m:workflowName>'

    + '<m:associationData></m:associationData>'

    + '</m:StartWorkflowOnListItem>'

    + '</soap:Body>'

    + '</soap:Envelope>';

 

 

 

 

NWF$.ajax({

  url: SiteURL + "/_vti_bin/NintexWorkflow/Workflow.asmx",

  beforeSend: function (xhr) {

         xhr.setRequestHeader("SOAPAction",   "http://nintex.com/StartWorkflowOnListItem");

         //POINT[1]

         //xhr.setRequestHeader ("Authorization", "Basic " + window.btoa("login:pass"));

  },

  type: "POST",

  dataType: "xml",

  data: sr,

   // POINT [2]

   // username: "login",

   // password: "pass",

    success: function () {

          alert("success");

     },

    contentType: "text/xml; charset=utf-8",

    error: function (requestObject, error, errorThrown) {

           alert(requestObject.status + " " + error + " " + errorThrown);  }

    });

}

 

 

Question:

    a.  How can I execute the above Web Service call to start a Nintex Workflow using either an elevated account (without POINT 2 issue happening).

    b.  OR  What permissions are required to execute the StartWorkflowOnListItem  web method @ "_vti_bin/NintexWorkflow/Workflow.asmx" from a user with CONTRIBUTE rights to the Sharepoint site.

    c.  Any other alternative solution ?

 

 

Many thanks for reading. Any help is much appreciated.!

 

Regards,

Jason

Outcomes