cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ameyholden1
Level: Powered On

Calling Flow from Custom Button in DYnamics

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

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 😞

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ameyholden1
Level: Powered On

Re: Calling Flow from Custom Button in DYnamics

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");
                                     
		}
    });
}

View solution in original post

2 REPLIES 2
Super User
Super User

Re: Calling Flow from Custom Button in DYnamics

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

 

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

 

Thanks

 

 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!



ameyholden1
Level: Powered On

Re: Calling Flow from Custom Button in DYnamics

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");
                                     
		}
    });
}

View solution in original post

Helpful resources

Announcements
firstImage

Better Together Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

firstImage

Incoming: New and improved badges!

Look out for new contribution recognition badges coming SOON!

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Community Summit North America

The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (8,024)