Click here to Skip to main content
15,888,802 members
Articles / Hosted Services / Azure

Fusion Development for Sales Apps Part 3: Working with Form Data

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
12 Apr 2022CPOL7 min read 3.5K   18   2  
In this article we create a custom connector, call the API, and create a reservation button.
Here we show you how to add the API we created to our Power App using a custom connector, demonstrate how to modify the Power App to call the API we created to look up and display vehicles that fit the filtering criteria, and add a button that will let the salesperson trigger the ‘reserve vehicle’ API call.

This fusion development series has demonstrated a great approach to learning how teams can leverage specific tools for a smoother development cycle.

The previous articles showed the vital role Azure plays in extending essential functions to a Microsoft Power App and making the app a better tool for selling cars. They also showed how to implement a database and an app service for systems to communicate with each other.

This third and final article explores how we can make our Power App more helpful for the sales team and create a rich user experience on different platforms. We’ll cover:

  • How to add the API we created in the previous article to our Power App using a custom connector.
  • How to modify the Power App to call the API we created in the previous article.
  • How to add a button that lets a salesperson trigger the reserve vehicle API call, ensuring nobody else sells a vehicle the customer wants. So, the salesperson can negotiate and close the deal after the test drive is complete.

Create a Custom Connector

A connector is a proxy for an API that allows the underlying service to talk to Power Apps. It provides a set of operations called triggers and actions.

Actions are user changes to a Power App. The Swagger OpenAPI defines actions. These changes can include actions to look up, write, update, or delete data in a PostgreSQL database. These actions enable users to find and display vehicles that fit specified criteria.

In contrast, functions and triggers listen for events and perform an action whenever the event is triggered. Pressing a button on a Power App is a trigger. For example, we create a reserve button in this article.

To create a custom connector, sign in to Power Apps. Navigate to Data, then to Custom Connectors.

Image 1

In the list of Custom Connectors, click New custom connector. Then, since we’re using OpenAPI, choose import an openAPI file.

Image 2

Enter a name in the Connector name field. Then navigate to the OpenAPI file you downloaded or created. Click Continue.

Image 3

Note: OpenAPI is currently on version three, which Power Apps does not support. Ensure to convert the JSON file to version two.

Image 4

The connector’s general information appears.

Image 5

Click Create Connector on the far right to create and save the connector.

It’s possible to set the connector’s security in the Security section. The Definition section is also essential, as it has all the connector’s required actions. Step 5 is Test, and this only happens after you have created a connector. You can test the API and get responses.

The Swagger Editor enables editing the fastAPI on the Power App without directly changing the openAPI file.

The screenshot below shows an example of the definition.

Image 6

The next step is to use the OpenAPI in our Power App using the connector we created. The diagram below shows the process flow:

Image 7

Modify the Power App to Call the Sales API

Next, we edit our Power App to call the sales API using the connector we created in the previous section. The connector is our data source instead of the Excel file.

To start, navigate to Apps on the Power Apps menu and edit the app. First, remove Google Sheets as your data source, so the app looks like the screenshot below:

Image 8

On the left-side panel, click Add data and pick the connector created above.

Image 9

Once the app data loads, the updated screen displays the data.

Image 10

In this instance, the app has the data and the connector, and we can add a search criterion.

Image 11

We can change "Search by ID" to "Search" in the HintText field of the Advanced properties on the right-side panel.

The next step adds filtering properties to the app. This step is vital for the sales team to know what vehicles are in stock. Then, we add an action to search by vehicle color or model.

To do this, click the Tree view menu on the left side panel. Click Screens, and select the Form layout under Screen1. When the items on the screen are selected, go to the fx function box and insert this function:

Python
Filter(FastAPI.getAll(),StartsWith(color, TextInput2.Text) || StartsWith(model, TextInput2.Text))

The Filter function requires two main components. These are:

  • Data source, the FastAPI.getAll function in this case. This function retrieves all the items listed in the Azure database (the Cars table) and populates the form layout.
  • Logic, the search criteria implemented in the filter function. In this case, we’ll use the StartsWith and or functions. The StartsWith function compares the text input in the search bar with any matching color or model in the form list.

When we play the app, we can filter the vehicles according to color or model.

Image 12

Image 13

This section explored how to implement the Search function using the Sales API in our app. With the efforts of both the citizen developer and professional developer, the app can pull data from the system and display it in the Power App.

Next, we add a reserve button. Whenever the button is triggered, there’s an update to the existing Azure database and the Power App.

Add a Button to Trigger the Reserve Vehicle API Call

The salesperson must click the view details arrow to reserve a vehicle, which opens a new screen (created below) and passes the vehicle’s details using the function below. The arrow’s OnSelect property configures this action:

Python
Navigate(NewScreen,ScreenTransition.CoverRight); Set(viewItem,ThisItem)

Our Navigate function comprises two parts:

  • ScreenTransition.CoverRight is the transition type from the main screen to the available screen.
  • The Set(variableName, value) helps create a variable. In this case, the variable name is viewItem, and the value is ThisItem. The code passes this variable to the new screen. The new screen opens when the user clicks the arrow.

Image 14

Click the Insert tab and select New screen to create a new screen. On the New screen menu, choose the blank screen option. The new screen is named "AvailableScreen."


Image 15

To add a data table to display the selected vehicle’s details, select data table on AvailableScreen’s Insert tab.

Next, add a data source to the table. Use this function to get a vehicle based on the Item_ID:

Python
FastAPI.getItem(viewItem.item_id)

The FastAPI.getItem function gets one vehicle by using Item_ID as a parameter. The viewItem object contains all the vehicle details passed from the previous screen.

Once the data source is configured, go to the table’s properties and click edit fields. This menu option allows you to select columns to display.

Image 16

To add the reserve button, click the button on the Insert tab and place it anywhere below the data table. You can change the button’s default text to "reserve" by changing the text option’s value in the button’s properties.

Image 17

Image 18

The button must run the FastAPI.updateItem function to reserve a vehicle. The code passes the vehicle ID, and a query runs to update the vehicle details for this function to run successfully.

Below is the code in the button’s OnSelect property:

Python
FastAPI.updateItem(viewItem.item_id);
Navigate(SuccessScreen,ScreenTransition.CoverRight)

Once the item is updated, the app transitions to a new screen that notifies the salesperson that they have successfully reserved the vehicle.

To create a new screen that displays the "successfully reserved" message, click New Screen and select Success from the menu.

The button should take a salesperson back to the main screen. Use the following code:

Python
Navigate(Screen1);

Finally, play the app and search for a vehicle.

Image 19

Click the arrow to view selected vehicle details (like the screenshot below), then click reserve.

Image 20

Image 21

The vehicle is reserved. We can search for the vehicle again, immediately seeing "Not Available."

Image 22

The Azure database also updates accordingly.

Image 23

Next Steps

In this article, we learned how to create a custom connector and add an existing API to a Power App. This section is beneficial to salespeople, as they can now work efficiently by looking up and updating the data. Citizen developers can simply add functions to connect to existing data or systems.

The fusion development approach has proven to be vital in development. All expertise is essential, and all experts work together to great advantage. Citizen developers focus on outlining the business problem and creating a prototype solution, while professional developers work with existing systems and connect the necessary resources.

Microsoft's Power Platform is more than the sum of its parts. It’s a suite of technologies supporting low-code development, making it relatively easy to generate a working app. Fusion teams can build incredible apps using most data sources on the Power App platform. They can also connect and import data using various custom connectors.

Explore the thorough Microsoft Power Apps documentation to learn more. And, if you’re ready to power up your sales apps and tackle other business challenges, get started with Power Apps.

To learn how Pro code development fits with Power Apps low code development and Why Pro Code and Low Code Developers need each other, check out our on demand digital event, Pro Code on a Low Code Platform.

This article is part of the series 'Fusion Development for Sales Apps View All

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --