Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to trigger a workflow on Save Button in CRM

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

  • Razim Khan Profile Picture
    Razim Khan 150 on at
    RE: How to trigger a workflow on Save Button in CRM

    thanks  Guillaume Domont

  • Suggested answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: How to trigger a workflow on Save Button in CRM

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to trigger a workflow on Save Button in CRM

    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
    Vardhan Profile Picture
    Vardhan 65 User Group Leader on at
    RE: How to trigger a workflow on Save Button in CRM

    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
    M.Azwar Alam Profile Picture
    M.Azwar Alam on at
    RE: How to trigger a workflow on Save Button in CRM

    Hi

    1- Trigger your custom workflow on on field change

    Mark answer as verified, if it works for you

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to trigger a workflow on Save Button in CRM

    Hi,

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

  • Razim Khan Profile Picture
    Razim Khan 150 on at
    RE: How to trigger a workflow on Save Button in CRM

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

  • Suggested answer
    Vardhan Profile Picture
    Vardhan 65 User Group Leader on at
    RE: How to trigger a workflow on Save Button in CRM

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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans