Calling a D365 web service from a Power App

Here is a guide on how one can utilize a Powerapp to call a D365FO custom web service. Please see my post Lets make a service if you need a guide on how to make a custom web service.

In power apps there are no built in way to do this directly, as I understand you need either to create a custom connector or call the web service through a Flow. In this post we will concentrate on the use of a Flow.


Crate a Power app

Begin by creating a blank power app. Add some controls similar to the image below, consists of a label, input text button and a label at the bottom. You now have a basic screen to enter information and pass to your web service.


Now we need to declare a variable, in the menu on the left, select your App and change the event to OnStart


In the formula input box declare a variable and notify a label of text change. 

Set(SearchResult, "Enter product ID and press search"); Notify(ResultLabel.Text)

Select your label to display the results (in my case ResultLabel) and change the event to Text, type in the variable name SearchResult (or what you called your variable). This will populate the text of the label to whatever is contained in the variable SearchResult.



Calling a Flow (that calls a Web Service)

We need to call the Web service, to do so we need to create a Flow. Select your button and change the event to OnSelect, then go to option pane Action and press the Power Automate button.

You will be presented with a dialog screen, press the Create a new flow button, now go here to see my guide on how to create a flow. You need to create a flow that asks for an access token and queries a web service. You can also select one of your previously created Flows if you have one, the new or selected Flow will be displayed in the Data pane on the left. The name of the Flow is the name you need to call it by in a function. The name is your Flow name without the white spaces or other not allowed characters.



Retrieve and display result from Flow

Select your button and change to the OnSelect event, in the function input type your call and set a variable. 

In my case the Flow is called Productnamesearchwebservice, takes one input and returns one parameter named product_name. We need to set the parameter SearchResult to the return parameter of the Flow. In my case this is done like this: 

Set(SearchResult, Productnamesearchwebservice.Run(TextInput.Text).product_name)

The syntax if something like this: 

Set([variable name], [Flow name].Run([Input text]).[return parameter name]).

After these steps are done you can test your app by pressing the play button in the top right corner. My web service takes a product number and returns the product name.








Comments

Popular posts from this blog

Call a simple Logic app from X++

SysOperationFramework with use of Query

Retail Attributes on sales lines