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.
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
- 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.
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.
To get the Weblink to the created Power App, we can go to the details page of the app
Select the WebLink URL which we will be using to create the link with appended Query parameters.
We will create two links by appending the query parameter named View and assigning Nurse and Admin as the respective values in the link
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
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.
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.
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
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
Same way for Admin Link, we will audience target it to the recently created Admin Security Group
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.
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.