Introduction
Hi Everyone,
Hope you are doing great and staying safe.
Today, in this blog post I am going to share PowerGuideTip25, where I'll demonstrate how to read Dynamics 365 security role using Power Automate and Integrate it with PowerApps - Canvas App.
There are umpteen business use cases, where we need to design the app/flow/process based on the Dynamics 365 security role. One of the best examples is:
Role-based Canvas App, where we need to navigate the user to different-2 screens or perform different process/flow based on the role assigned in the CRM application.
Business Requirement
- Create a mobile app for the Sales Team.
- Sales Agent will login into the app to track his/her daily appointment, track customer location, capture meeting notes, and assign tasks to the sales manager for approval
- Sales Manager will log into the app in order to track the sales team's performance and approve the request made by a sales agent.
Pre-Requisites
- PowerApps License (PerApp or Per User) or can use Trial as well.
- Dynamics 365 License or use Trial as well.
- Must have two users. One user must have a Sales Person Role and another user must have a Sales Manager role to test the flow.
- Download the Power Automate from my GIT Repository.
Solution Architecture
Steps to Implement
Download Power Automate from GIT HUB
Steps to Use the Power Automate Solution
- Click on My Flows from the Left Panel and Click Import
- Browse the downloaded Power Automate zip file and Hit Upload.
Note: Change the Common Data Service (Current Environment) connection
Design a Canvas App
I have designed a sample canvas app for Sales Agent and Sales Manager.
App has 4 screens -
- Landing Screen - where the user will be landed after a successful login.
- Profile Screen - Display logged-In user information
- Error Screen - This screen will display an "Insufficient Permissions" message if a user doesn't have the appropriate role assigned in the CRM Application
- My Roles - This screen will display all security roles assigned to the logged-in canvas app user.
App Flow:
- Sales Agent or Sales Manager will log in to the app.
- If Sales Person has Sales Person security role assigned in D365, Redirect the user to Profile Screen else Redirect to Error Screen
- If Sales Manager has Sales Manager security role assigned in D365, Redirect the user to Profile Screen else Redirect to Error Screen
Add the following expression on OnSelect property of the 'Login as Sales Person' button.
// Call Power Automate
Set(FlowOutput,GetD365UserRole.Run(LookUp(Users,domainname=User().Email).systemuserid));
// Check if Power Automate Output contains 'sales person' then Navigate to profile Screen else Navigate to Error Screen.
If(IsMatch(FlowOutput.userrole,"sales person",Contains & IgnoreCase),Navigate(ProfileScreen,ScreenTransition.Cover),Navigate(ErrorScreen,ScreenTransition.Cover))
Add the following expression on OnSelect property of the 'Login as Sales Manager' button.
// Call Power Automate
Set(FlowOutput,GetD365UserRole.Run(LookUp(Users,domainname=User().Email).systemuserid));
// Check if Power Automate Output contains 'sales manager' then Navigate to profile Screen else Navigate to Error Screen
If(IsMatch(FlowOutput.userrole,"sales manager",Contains & IgnoreCase),Navigate(ProfileScreen,ScreenTransition.Cover),Navigate(ErrorScreen,ScreenTransition.Cover))
Use the following expression on
OnSelect property of
'View my Roles' button.
Navigate(MyRoles,ScreenTransition.CoverRight);
Add
List Screen and change it's Layout to 'Title' type.
Set following expression on 'Items' property of List screen
Split(FlowOutput.userrole,",");
This expression will split the security role list (returned from power automate in comma separated format) to table
Test & Demo