web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to trigger a workflow on Save Button in CRM

(0) ShareShare
ReportReport
Posted on by 150

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

I have the same question (0)
  • Suggested answer
    Vardhan Profile Picture
    65 User Group Leader on at

    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”.

  • Razim Khan Profile Picture
    150 on at

    in above code i only need  to pass my workflow GUID ??

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    Why don't you register your custom workflow on the update of the record? It will be triggered every time you save it.

  • Suggested answer
    M.Azwar Alam Profile Picture
    on at

    Hi

    1- Trigger your custom workflow on on field change

    Mark answer as verified, if it works for you

  • Suggested answer
    Vardhan Profile Picture
    65 User Group Leader on at

    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

  • Suggested answer
    Community Member Profile Picture
    on at

    Hello,

    You can try doing it with the Process.js library.

    here processjs.codeplex.com

    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.

  • Suggested answer
    ashlega Profile Picture
    34,477 on at

    +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)?

  • Razim Khan Profile Picture
    150 on at

    thanks  Guillaume Domont

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans