Hi Everyone,
there is a requirement , that how to trigger a custom workflow when save button is clicked in dynamic crm.
any help will be appriciated. thanks
*This post is locked for comments
Hi Everyone,
there is a requirement , that how to trigger a custom workflow when save button is clicked in dynamic crm.
any help will be appriciated. thanks
*This post is locked for comments
thanks Guillaume Domont
+1 for Guillaume
Why do you need to trigger it manually (through javascript) if you can simply register it on the create of the record and on the update of the attributes? (which is the same as triggering it onsave, essentially)?
Hello,
You can try doing it with the Process.js library.
And with this snippet you could trigger your workflow.
Process.callWorkflow("4AB26754-3F2F-4B1D-9EC7-F8932331567A",
Xrm.Page.data.entity.getId(),
function () {
alert("Workflow executed successfully");
},
function () {
alert("Error executing workflow");
});
Hope this helps you.
Yes you only need to pass Guid of the Workflow. Easy way is to register your custom workflow on change of the Updating Fields as suggested other.
Mark as verified if that works
Hi
1- Trigger your custom workflow on on field change
Mark answer as verified, if it works for you
Hi,
Why don't you register your custom workflow on the update of the record? It will be triggered every time you save it.
in above code i only need to pass my workflow GUID ??
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”.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,269 Super User 2024 Season 2
Martin Dráb 230,198 Most Valuable Professional
nmaenpaa 101,156