BookmarkSubscribeRSS Feed

How to Create a Decision App with SAS Container Runtime and Microsoft Power Apps

Started ‎12-13-2021 by
Modified ‎12-13-2021 by
Views 6,637

Watch the video where a user, with no coding skills, can call (score) a SAS decision, from an app on his mobile phone. Read the article to understand the integration between Microsoft Power Apps and a SAS decision published to Azure with SAS Container Runtime. The decision is deployed to an Azure Web App and called through a REST API.

 

A SAS Decision Scored from Microsoft Power Apps

 

Steps

  • Develop and test the decision in SAS Intelligent Decisioning.
  • Publish the decision to Azure as a SAS Container Runtime (SCR) image.
  • Deploy the SCR image to an Azure Web Application.
  • Develop a flow in Microsoft Power Apps.
  • Create the application in Microsoft Power Apps.
  • Publish the application.

 

 

The first two steps were explained in detail in How to Publish a Decision to Azure with SAS Container Runtime.

 

Deploy the SCR image to an Azure Web Application

In your Azure portal, create a Web App. Select Publish > Docker Container:

 

bt_1_810-Create-Azure-Web-App-from-SAS-Container-Runtime-image-1.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

Only if you have an App Service plan, select it. Azure App Service plans might be discussed in a future article.

 

In the Docker tab:

 

bt_2_812-Create-Azure-Web-App-from-SAS-Container-Runtime-image-2.png

 

 

Further, go to Review and Create.

 

After deployment, the web application URL will be https://AppName.azurewebsites.net/ while the SCR REST API will listen on https://AppName.azurewebsites.net/SCRimagename:8080 .

 

 

bt_3_815-Azure-Web-App-from-SAS-Container-Runtime-URL-1024x189.png

 

 

Specific to SCR container images, you need to tell Azure on which port the SCR REST API will be listening.

 

From Settings > Configuration, create a new application setting called WEBSITES_PORT with the value 8080.

 

bt_4_818-Azure-Web-App-from-SAS-Container-Runtime-port-8080-1024x790.png

 

From now on, all traffic sent to https://AppName.azurewebsites.net/SCRimagename will be sent through port 8080.  

 

Develop a flow in Microsoft Power Apps

Note: To complete the following steps, you will require a Premium Power Apps license.

 

The SCR REST API returns a JSON string. However, Power Apps cannot convert directly the JSON string into data.

 

One of the possible solutions is to use a flow. The flow collects inputs, passes them to the Azure Web App (SCR runs inside), then it parses the JSON for Microsoft Power Apps:

 

bt_5_820-MS-Power-Apps-Flow-to-call-SAS-Container-Deployed-to-Azure.png

 

Go to Power Apps > Flows and create a new flow.

 

Here, the app runs the flow, which calls an Azure Web App, with a SCR decision inside.

Inputs

Inputs from the application are expected as strings. You require one Initialize variable step per input.

bt_6_822-MS-Power-Apps-Flow-input-variables-1024x793.png

 

REST

The HTTP step is calling the SCR REST API, listening inside the Azure Web App at https://APPName.azurewebsites.net/SCRimagename .

 

 

bt_7_825-MS-Power-Apps-Flow-HTTP-step-calling-a-SCR-decision-1024x793.png

 

 

The request body is parametrized with the input variables collected.

 

String inputs from Power Apps must be converted to numeric if the decision expects numeric inputs. Therefore, it is your job to know what data types the decision inputs and outputs are. You have to match or convert them to the expected application input data types.

 

On a side note, the flow HTTP step and the curl command below will produce the same results:

 

bt_8_826-Scoring-a-SCR-decision-with-curl.png

 

You can read more about scoring commands in How to Score a SAS Decision Published to Azure with SCR.

 

Post-processing

The last three steps will convert the response, from a JSON string, into an array, that can be parsed inside Power Apps.

bt_9_828-MS-Power-Apps-Flow-parse-json.png

Create the application in Microsoft Power Apps

The application created is deliberately minimalistic. There is one screen for the inputs, the action button and the decision output.

 

Inputs

Inputs are collected through text labels, just like in a web form.

 

bt_10_836-MS-Power-Apps-Decision-App-Output-1024x859.png

 

Connect the app with the data source

The Power Automate flow becomes the data source.

 bt_11_832-MS-Power-Apps-Decision-App-Power-Automate-Flow-1024x722.png

 

The action button calling the SCR decision

 

bt_12_835-MS-Power-Apps-Decision-App-Button-Calling-Flow-1024x859.png

 

The button’s OnSelect property is perhaps the most important in this app:

  • Runs the flow with the expected parameters:
AutoAuctionFlow.Run(state.Text,Make.Text,Model.Text,CurrentBid.Text,BlueBookPrice.Text,Miles.Text)
  • Creates a collection bidInfo in Power Apps. Then, it populates the table with the data from the flow. The collection is like a table inside the application.
 ClearCollect(
    bidInfo,
    AutoAuctionFlow.Run(state.Text,Make.Text,Model.Text,CurrentBid.Text,BlueBookPrice.Text,Miles.Text)            );

 

The decision output

From the collection bidInfo, the bidCommand value is selected and displayed. The label represents the SAS decision output.

bt_13_836-MS-Power-Apps-Decision-App-Output-1024x859.png

 

Publish the application

When you tested the application sufficiently, you can publish or share the application with other users in your organization.

 

Download PowerApps from Apple Store and you can use the application you created instantly.

 

 

888_8 Power Apps Decision Application communities.jpeg

 

 

 

Conclusions

You can score SAS decisions, or models, from a Microsoft Power Apps application. This approach increases dramatically the audience and the consumption of SAS decisions and models. Microsoft Power Apps provides a low-code development environment. The Microsoft Power Apps application calls the SAS decision published to and running in Azure, through the SAS Container Runtime REST API.

SAS documentation

SAS Communities and YouTube

Thank you for your time reading this article. If you liked the article, give it a thumbs up. Please comment and tell us what you think about the new SCR and Azure publishing destination.

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
‎12-13-2021 12:15 AM
Updated by:
Contributors

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started