While playing around cards for Power Apps, I noted that the User Power Fx function that is used in Canvas Apps to detect the current user and get some information about it is not supported.
After some investigation, I found that Cards use a new object called Viewer instead.
How to use the Viewer Object
The viewer object has 3 properties that potentially we could use to filter data by the Current User :
- name: it’s the user Display name
- aadObjectId: ID of the user in Azure AD
- id: weirdly this displays the UPN when loading in the Cards player but it displays something that seems like a Teams identifier when sending the Card in Teams, for example: 29:16a03jETMRncoewiNAeiWgBqzzxv-Rx16996NUHRjgNHW8Bb7449q-Y3ku9-s4a3ZE3AR_e0NQiM-6qx2n3vWIw
Filtering data by the display name can be messy as there could be two people with the same name in the tenant, so going with the aadObjectId would be the most precise way.
Filtering Data
Let’s say you wanted to filter all items created by a user in a Dataverse table and display the list in a Fact Set, you could use the filter formula similarly to what you would do in a Canvas app, by using the ‘Created By’ and the ‘Azure AD Object Id’ as below:
Filter('Your Table Name','Created By'.'Azure AD Object ID' = GUID(Viewer.aadObjectId))
Important to note that as of now, delegation is not supported for the Filter function in Cards.
To use the returned values in the Fact set, you need to use the following syntax in the Title/Value props:
=ThisItem.prefix_yourcolumnlogicalname
You can also use the LookUp function to filter results by current user (only one object returned as in a Canvas app). Weirdly the LookUp supports delegation but does not support filtering data by a column other than the Id column:
Results
When running in the player/pasting your card in Teams, you’ll get the filtered items from your table:
Conclusion
By using the Viewer.aadObjectId property we can filter data associated/created by the current user in cards. Bear in mind delegation does not work fully in cards yet. Hopefully, full support for delegation will be added in a near future.
[…] Source link […]
[…] Filtering Dataverse data by the current user in Cards for Power Apps […]
Hi
Thanks for this post. I have just helped a colleague by referring to this post . In our canvas app: gallery we a can’t use the personalised view Filter(‘Training Courses’, ‘Training Courses (Views)’.’My Courses’).
The view : Instructor is current user works fine when viewed in Dataverse. Your approach works fine.
No problem, great that it works for you😊