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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Calling Flow from Cust...
Power Automate
Answered

Calling Flow from Custom Button in Dynamics

(0) ShareShare
ReportReport
Posted on by 26

I'm having trouble writing the command/javascript for a custom button in Dynamics.

 

I want to be able to press a button in Dynamics which calls a flow to do various things e.g. update the status of a record and start an approvals process - all I want to send is the record GUID to flow so that I can trigger the relevant actions in Flow. 

 

Kind of similar to this but instead of var pathObj being a fixed string I want this to be the record GUID

var pathObj = { "path": "/Account/" };

https://community.dynamics.com/crm/b/magnetismsolutionscrmblog/posts/how-to-trigger-a-microsoft-flow-from-a-custom-button-in-dynamics-365

Can someone help me with what the JavaScript command would look like which is called on the button? I know it's probably very simple but I've read endless blogs and spent all day tearing my hair out trying to do it. Feeling very defeated 😞

 

 

Categories:
I have the same question (0)
  • abm abm Profile Picture
    32,865 Most Valuable Professional on at

    Hi @ameyholden1 

     

    Which version of Dynamics are you using? Version 9 onwards Xrm.Page is deprecated. To get the Id you need to get the formContext. Have a look at below articles how to get the GUID

     

    https://debajmecrm.com/2018/11/16/xrm-page-is-deprecated-with-version-9-0-how-do-i-get-the-clienturl-and-form-data-in-ribbon-actions/

     

    https://carldesouza.com/dynamics-365-client-api-changes-globalcontext/

     

    Thanks

     

     

  • Verified answer
    ameyholden1 Profile Picture
    26 on at

    Thanks for your suggestions and response @abm I really appreciate it. The issue was actually with my code where I was parsing the JSON - updated code below which works a dream so we can close this thread 🙂

     

    function sendFlowRequest(formContext)
    { 
    	var CJGuid = formContext.data.entity.getId();
    	CJGuid = CJGuid.replace(/[{}]/g,"");
    	parent.$.ajax
    	({
     type: "POST",
     url: "**FLOW URL HERE**",
     contentType: 'application/json',
     data: JSON.stringify({"CJGuid" : CJGuid}),
    		success: function () 
    		{
     alert("success");
     
    		}
     });
    }
  • matscho Profile Picture
    2 on at

    Hey,

    I have a similar problem, where i want to start a flow via a button on the ribbon. My only problem is the authentication with the http request. Have you left your http request open for anyone or did you accomplish to authenticate your user for the http request? (using Oauth2)

  • ameyholden1 Profile Picture
    26 on at

    When I implemented this the only option on http requests was to have it open to anyone. I doubt it would be possible to do with the authenticated option due to the nature of triggering the request via JS there is no authentication pass through. If you want to lock down to authenticated I would suggest using a button to pop out a custom page as a modal, and run the flow in the 'OnStart' property of the custom page.

     

    Like this but without the user inputs, you would just need some kind of 'Loading/In progress' message and then a success response/button to close etc. I've been meaning to write up a blog post on this exact thing... thanks for the reminder!

     

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard