Working with Query Parameters in Power Apps

Introduction

Passing of Query Parameters in URL is something we used to leverage most often when we wanted to pass an input parameter to an application URL so that we can extract the parameter and process the application based on the passed Input. This makes the application more dynamic and helps prevent the duplication of the application to cater to multiple audiences. The application can still contain the logic for multiple audiences and based on the query parameter that identifies the targeted audience using it, we can show the needed side of the application and intentionally abstract or hide the rest of the application from the current user.

Similarly in Power Apps, most often, we have to set the start screen or show specific screens based on the users using it. In this article, we will see how to Pass Query parameters to Power App from a Web Application like SharePoint and show the start screen based on the Query parameter.

Scenario

We have created a Medicine Inventory App that is used by Nurses to keep track of Incoming and Outgoing Medicines. It has 2 screens:

  • Nurse View – That provides the nurses with the incoming and outgoing stock modification options
Timeline

Description automatically generated
  • Admin View : That provides a super admin with the report generation and analytics viewing option in addition to the default incoming/outgoing stock update buttons.
A picture containing graphical user interface

Description automatically generated

We will see how to Provide the Link to the Power App on SharePoint Page in such a way that Nurses will be able to see only the Nurse Link on the SharePoint page and the Admins will see only the Admin Link. Clicking on it would open the Power App with their respective screens.

Graphical user interface

Description automatically generated with medium confidence

Implementation

To get the Weblink to the created Power App, we can go to the details page of the app

Graphical user interface, text, application, chat or text message

Description automatically generated

Select the WebLink URL which we will be using to create the link with appended Query parameters.

Graphical user interface, text, application, email

Description automatically generated

We will create two links by appending the query parameter named View and assigning Nurse and Admin as the respective values in the link


Nurse View Link :

https://apps.powerapps.com/play/4002208c-8de3-41a4-b29b-774d69378fb8?tenantId=b3629ed1-3361-4ec4-a2b7-5066a5c5f?View=Nurse

Admin View Link :

https://apps.powerapps.com/play/4002208c-8de3-41a4-b29b-774d69378fb8?tenantId=b3629ed1-3361-4ec4-a2b7-5066a5c5f?View=Admin

Consume the Parameter in PowerApp

We will now see how to extract the Query parameter named “View” inside the Power App and switch the screen based on its value.

Power App has a Start Screen Property for the App where we will specify the below expression that reads the Query parameter using the Param function and based on the value, we will set the start screen

If(Param(“View”)= “Admin”,Screen_AdminView,Screen_NurseView)

Here the expression checks the query parameter named View and if its value is Admin, it sets the Admin Screen as start screen else it sets the Nurse Screen as start screen.

Graphical user interface

Description automatically generated

Adding the Query Parameter Links to SharePoint

Now, let’s see how to set the Nurse and Admin Links in SharePoint and Audience Targeting for the links so that the Links will be visible to Nurses or Admin based on their existence in an AD Security group. This was we can ensure that Nurses don’t see Admin Link and thereby not giving them unintentional access to the admin view.

As the first step, let’s edit the SharePoint page where we want to add the links and add a Quick Links Web part. We will also add the links to both Nurse and Admin View.

Graphical user interface, application

Description automatically generated

As we can see above, we have not updated the Audience to the target section. Let’s create 2 Security Groups in Azure AD for Nurse and Admin and update the Audience Target sections as well

Graphical user interface, text, application, email

Description automatically generated

Let’s head back to the Quick Links web part and update both the links with the respective groups so that only members of that SharePoint group will be able to see the corresponding links. We will add the Nurse Security group against the Nurse View Link

Graphical user interface, text, application, chat or text message

Description automatically generated

Same way for Admin Link, we will audience target it to the recently created Admin Security Group

Graphical user interface, text, application, chat or text message, website

Description automatically generated

Test the Audience Targeting and View Change

Now I have removed myself from the Admin Security Group and heading to the SharePoint page, we can see that only the Nurse view link is visible.

Clicking on it will take us to the Power App and show us the Nurse Screen as the start page. Similarly, if we remove ourselves from the Nurse Security group and add in the Admin group, only the Admin Link will be visible on the SharePoint page, and clicking on it will take us to the Admin Screen of the Power App.

Note: If you have recently created the Group or have modified it, it would take some time for the targeting to be applied.

Summary

Thus we saw how to Audience Target Power Apps using Security Groups, Pass Query parameters via a weblink and switch start screen based on the Query parameter.

Related Articles

Author

Author

Priyaranjan KS is a Modern Workplace Architect primarily focused on developing and architecting solutions around Office 365,Power Platform and Azure.He is also a Microsoft Most Valuable Professional(MVP) and a Microsoft Certified Trainer(MCT)

Latest Articles