PowerApps – Get Dynamics 365 Logged In User Role in Canvas App

 

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
Download the Power Automate from my GIT HUB repository.
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

Error Screen
Test & Demo

Published by arpitpowerguide

My name is Arpit Shrivastava, who is a Microsoft MVP in the Business Applications category. I am a Microsoft Dynamics 365 and Power Platform enthusiast person who is having a passion for researching and learning new things and acquiring immense knowledge. I am providing consistent help, support, and sharing my knowledge through various Social Media Channels along with my Personal Blog, Microsoft Community, conducting online training and attending various 365 Saturday Events worldwide and sharing the best Solutions to the readers helping them achieve their goals and objectives in Customer Relationship Space.

8 thoughts on “PowerApps – Get Dynamics 365 Logged In User Role in Canvas App

  1. Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time. Contact him now and thank me later.

    Like

  2. Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time. Contact him now and thank me later.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: