Get the logged in users Dynamics user record ID in a Canvas PowerApp
When working with a canvas PowerApp that integrates into Dynamics 365, you occasionally need the current users’ Dynamics user GUID. This could be used to populate lookup references on the various records within Dynamics.
The user details provided by the User function within a Canvas app relates to the Office 365 user account of the logged in user. We know that for a single user, who has access to multiple Dynamics environments, there is no guarantee that their Dynamics user GUID would be the same in those environments. The Office 365 account/credentials used to access these various environments is the same however. With this in mind, this is how I get the logged in users Dynamics GUID.
- 1 – Create a data source connecting to the Dynamics Users entity
- 2 – Get the current logged in users’ profile, using the PowerApps user function, and create a variable placeholder(considered best practice to store it in a variable):
- 3 – Query the User data source, created from Step 1, and filter on matching the domain name on the user record to the current users’ email address and return the ‘systemuserid’ property i.e the user’s Dynamics 365 user GUID
You can then add a label, for testing purposes, on your canvas app and bind the text to the variable above to ensure that it’s worked correctly!
This has always worked for me but I’m keen to know how others have catered for this scenario so if you have done it before or have some ideas, let me know!