Trigger WorkFlow Using JavaScript – MS CRM 2011

Trigger WorkFlow Using JavaScript

var workflowGuid = “<Work Flow GUid>”;
var entityId = “<Record Guid>”;

function TriggerWorkflow(entityId,workflowGuid) {

/*Generate Soap Body.*/

var soapBody = “<soap:Body>” +
” <Execute xmlns=’http://schemas.microsoft.com/crm/2007/WebServices’>&#8221; +
” <Request xsi:type=\’ExecuteWorkflowRequest\’>” +
” <EntityId>” + entityId + “</EntityId>” +
” <WorkflowId>” + workflowGuid + “</WorkflowId>” +
” </Request>” +
” </Execute>” +
“</soap:Body>”;

/*Wrap the Soap Body in a soap:Envelope.*/
var soapXml = “<soap:Envelope ” +
” xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/&#8217; ” +
” xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance&#8217; ” +
” xmlns:xsd=’http://www.w3.org/2001/XMLSchema’>&#8221; +
GenerateAuthenticationHeader() +
soapBody +
“</soap:Envelope>”;

/* Create the XMLHTTP object for the execute method.*/
var xmlhttp = new ActiveXObject(“Msxml2.XMLHTTP”);
xmlhttp.open(“POST”, “/MSCRMservices/2007/crmservice.asmx”, false);
xmlhttp.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);
xmlhttp.setRequestHeader(“SOAPAction”, “http://schemas.microsoft.com/crm/2007/WebServices/Execute&#8221;);

/* Send the XMLHTTP object. */
xmlhttp.send(soapXml);
alert(“The workflow has been triggered successfully”);

}

 

Cheers,

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s