/* Function to call an On Demand WorkFlow on a Button Click */
crmForm.SaveAndClose();
try {
var PhoneCallId = crmForm.ObjectId;
var authenticationHeader = GenerateAuthenticationHeader();
//Prepare the SOAP message.
var xml = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
authenticationHeader +
'<soap:Body>' +
'<Execute xmlns="http://schemas.microsoft.com/crm/2007/WebServices">' +
'<Request xsi:type="ExecuteWorkflowRequest">' +
'<EntityId>' + PhoneCallId + '</EntityId>' +
'<WorkflowId>17E32F08-5D51-460E-B5A6-67AAEED92F20</WorkflowId>' +
'</Request>' +
'</Execute>' +
'</soap:Body>' +
'</soap:Envelope>'
var xHReq = new ActiveXObject('Msxml2.XMLHTTP');
xHReq.Open('POST', '/mscrmservices/2007/CrmService.asmx', false);
xHReq.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/crm/2007/WebServices/Execute');
xHReq.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xHReq.setRequestHeader('Content-Length', xml.length);
xHReq.send(xml);
var resultXml = xHReq.responseXML;
if (resultXml) {
return resultXml.selectSingleNode("//Response/Id").nodeTypedValue;
}
crmForm.ui.Close();
}
catch (e) {
alert("Failed to Execute");
}
return null;
}
No comments:
Post a Comment