<div id='codeeditor1-template'>
<script>
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function(){
var parameters = [ { Name: 'ConfirmationEmail', Value: 'test@test.com' } ];
StartWorkFlow("http://demo.sobiens.com", "http://demo.sobiens.com/Lists/Test/12_.000", "0B5BCDFE-62EE-4096-A41B-B30B566D06A0", parameters, function () {
console.log("completed")
});
getContentTypes("http://demo.sobiens.com","Test list")
});
function StartWorkFlow(webUrl, itemUrl, templateId, parameters, callback) {
var parameterString = "";
for (var i = 0; i < parameters.length; i++) {
parameterString += "<" + parameters[i].Name + ">" + parameters[i].Value + "</" + parameters[i].Name + ">";
}
var soapEnv =
"<?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> \
<StartWorkflow xmlns=\"http://schemas.microsoft.com/sharepoint/soap/workflow/\"> \
<item>" + itemUrl + "</item> \
<templateId>" + templateId + "</templateId> \
<workflowParameters><Data>" + parameterString + "</Data></workflowParameters> \
</StartWorkflow> \
</soap:Body> \
</soap:Envelope>";
$.ajax({
url: webUrl + "/_vti_bin/workflow.asmx",
beforeSend: function (xhr) {
xhr.setRequestHeader("SOAPAction",
"http://schemas.microsoft.com/sharepoint/soap/workflow/StartWorkflow");
},
type: "POST",
dataType: "xml",
data: soapEnv,
complete: function (msg) {
if (callback != null)
callback();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("An error occured on StartWorkFlow");
console.log(textStatus);
console.log(errorThrown);
},
contentType: "text/xml; charset=utf-8"
});
}
</script>
</div>
You can initiate a SharePoint workflow with the following javascript code;
Parameters can be used send parameter into SharePoint workflow.
CODE