Hi Razim Khan,
call TriggerWorkflow() below function on save of the record.
//function to run the workflow
function TriggerWorkflow() {
try {
if (Xrm != 'undefined' && Xrm != null) {
var entityId = Xrm.Page.data.entity.getId();
alert("entityId: " + entityId);
if (entityId != 'undefined' && entityId != null) {
CallWorkflow(entityId);
}
}
} catch (e) {
alert("RunWorkflow error >> " + e.description);
}
}
function CallWorkflow(entityId) {
/*Generate Soap Body.*/
var request = "" + "<request i:type='b:ExecuteWorkflowRequest' xmlns:a='schemas.microsoft.com/.../Contracts' xmlns:b='schemas.microsoft.com/.../Contracts'>"
+ "<a:Parameters xmlns:c='schemas.datacontract.org/.../System.Collections.Generic'>"
+ "<a:KeyValuePairOfstringanyType>"
+ "<c:key>EntityId</c:key>"
+ "<c:value i:type='d:guid' xmlns:d='schemas.microsoft.com/.../Serialization'>" + entityId + "</c:value>"
+ "</a:KeyValuePairOfstringanyType>"
+ "<a:KeyValuePairOfstringanyType>"
+ "<c:key>WorkflowId</c:key>"
+ "<c:value i:type='d:guid' xmlns:d='schemas.microsoft.com/.../Serialization'>5AE89DDD-8F82-4A50-9A56-771A6CF9778B</c:value>"
+ "</a:KeyValuePairOfstringanyType>"
+ "</a:Parameters>"
+ "<a:RequestId i:nil='true' />"
+ "<a:RequestName>ExecuteWorkflow</a:RequestName>"
+ "</request>";
try {
//Call the function to execute the workflow
XrmServiceToolkit.Soap.Execute(request);
} catch (e) {
alert("TriggerWorkflow error >> " + e.description);
}
}
Note: The below code uses XrmServiceToolkit. Please find the same at the following link xrmservicetoolkit.codeplex.com
In the above code you need to pass Workflow Id/Guid as we passed here “5AE89DDD-8F82-4A50-9A56-771A6CF9778B”.