cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DynamicsHulk
Frequent Visitor

Dynamics 365 : Setting Action Output Parameter using WebHook

Hi everyone,

 

I created an Azure Function that is called from CRM via WebHook. It is linked with action in CRM. Calling the action new_APITest triggers the execution of the Function. 

Fair enough, input parameters of the action are passed on to the Function. However, I do not know how to transfer the output parameters from the Function to the action.

Does anyone know the correct way to create the response of the Function? I've already tried some different approaches, but none has worked for me so far.

Is there a way to inject output parameters directly, without the need for creating a separate plugin?

 

Thank you.

-Sri

1 ACCEPTED SOLUTION

Accepted Solutions
DynamicsHulk
Frequent Visitor

Thanks, @cchannon , This issue got resolved by creating the record at dynamics for output params which I am using for different logic and deleting that record, I don't think we can set the output parameter for the action within the azure function.

View solution in original post

4 REPLIES 4
cchannon
Super User
Super User

I might be mistaken here, but I am pretty sure the only supported mechanism for letting your azure-executing code push a response back to a plugin (and therefore, have the plugin await that Azure execution) is to use a two-way Relay, not the Webhook. The Webhook will fire and end - it will not await completion. Likewise for all the Service Endpoint types (queue, topic, one-way, Rest, Event Hub) EXCEPT two-way.

 

The two-way service endpoint uses an Azure Service Bus Relay, publishing a WCF contract, to give you an endpoint you can call to pass your pluginexecutioncontext to. Then, on the Listener side, you can instantiate a "remoteexecutioncontext" which mirrors the plugin one and it just happens pretty much magically. (really convenient, actually). Then, when you're done in that Function or Web Job or Console app or whatever, you can return a string to your plugin which has been quietly awaiting the whole time.

 

Getting this to work can be a bit tricky, but let me try to smooth it out for you:

  • Get your samples code here
  • Read the docs here
  • Spin up an Azure Relay in your Azure Subscription, and set up a SAS on the relay (docs)
  • Start the sample code console app and enter the info from your relay/SAS then Name the actual endpoint (perfectly fine if it is the same name as the Relay)
  • Open the Plugin Reg tool (actual plugin reg tool - not the XRM Toolbox one) and register a new Service Endpoint. Enter the same data you put into the console app and set it as a Two-Way Service Endpoint (docs).
  • Register a new step under that Service Endpoint (i.e. Create of Contact)
  • Initiate a transaction that will fire the step. 

If everything was set up correctly, your transaction should be able to push its full pluignexecutioncontext out to your console app, and you will see the transaction come in within a second or two. Now, this isn't the whole story - it is only how to push a message out to the relay and not how to reply. To get the reply you will need to follow the documentation instructions to create a Custom Plugin using a Service Endpoint, and then that plugin can await the call and get a string response back from your console app.

 

Best of luck - and let me know if you get tripped up anywhere. I am planning to write a blog on this for the community because it is really under-utilized, IMHO.

I want to call out one step up above in particular because it tripped me up for a while the first time I did this. When you run the console app, it actually registers the relay endpoint itself. This is how the the dynamic relay endpoints work: they only exist if there is a listener listening to them (very neat idea, actually). So once you've created the relay and the SAS, you are DONE in Azure. The Console app will create the actual endpoint just magically when it starts to listen.

cchannon
Super User
Super User

Hi @DynamicsHulk - Did my response help resolve your issue? If so, please mark the solution for future visitors of your post, otherwise update us on how you resolved it!

DynamicsHulk
Frequent Visitor

Thanks, @cchannon , This issue got resolved by creating the record at dynamics for output params which I am using for different logic and deleting that record, I don't think we can set the output parameter for the action within the azure function.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Users online (3,920)