Skip to main content

I want to start a site workflow using JS and pass a value to the start parameter. See my code below. The workflow runs perfectly however, I'm not able to retrieve the value of the start parameter. 

function ResetLetter() {
var waitingDialog;
// var waitingDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Your action is in progress...', "Please wait while we generate the tasks for you.");
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
waitingDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Your action is in progress...', "Please wait while we generate the tasks for you.");
});

var $request = new Sys.Net.WebRequest();
var siteUrl = "http://testservices.goys.gov.bh/sys/e-cms1/";
$request.set_url((siteUrl || _spPageContextInfo.webServerRelativeUrl.replace(/^s+|s+$/gi, '')) + "/_vti_bin/NintexWorkflow/Workflow.asmx");
var $headers = $request.get_headers();
$headerse"Content-Type"] = "text/xml; charset=utf-8";
$headerse"SOAPAction"] = "http://nintex.com/StartSiteWorkflow";
$body = "<?xml version=""1.0"" encoding=""utf-8""?>" +
"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" +
"<soap:Body>" +
"<StartSiteWorkflow xmlns=""http://nintex.com"">" +
"<workflowName>{0}</workflowName>" +
"<AssociationData>{1}</AssociationData>" +
"</StartSiteWorkflow>" +
"</soap:Body>" +
"</soap:Envelope>";
var thisArgs = this;
$request.add_completed(function (executor, args) {
var statusCode = executor.get_statusCode();
if (statusCode >= 200 && statusCode <= 399) {
Sys.Debug.trace("Action terminated");
} else {
Sys.Debug.trace('Warning : Error (Status code {0})', statusCode);
alert('Error');
}
waitingDialog.close();
});

$request.set_body(
String.format($body, 'WF-GetLetterRef', '<Data><LetterRef>1907</LetterRef></Data>'));
$request.invoke();
return false;
}

A simple way to start a workflow could be the following.

-Create a list named "WFStarter" with a column named "myParameter"

-Create a workflow on that list, that starts on item creation

-From Javascript (REST or CSOM) create a new item on "WFStarter".


That's also another smart way of doing it. My issue was xml is case sensitive so therefore I changed  <AssociationData> to <associationData>


So many thanks - I didn't see this anymore, but that did the trick for me.


Reply