DataSourceInfo function can be used to check the Table / Entity level permission.
We can check for Create, Read, Edit, and Delete Permission and can disable, hide and show the corresponding create, edit and delete buttons for the users.
- DataSourceInfo.CreatePermission
- DataSourceInfo. DeletePermission
- DataSourceInfo. EditPermission
- DataSourceInfo. ReadPermission
DataSourceInfo function can also be used to obtain information about a particular column of the data source like Display Name, Max Length, Max Value, Min Length, Required.
https://www.inogic.com/blog/2020/11/how-to-use-datasourceinfo-in-canvas-app/
- DataSourceInfo.DisplayName
- DataSourceInfo.MaxLength
- DataSourceInfo.MaxValue
- DataSourceInfo.MinValue
-
DataSourceInfo.Required
Similarly, the RecordInfo function can be used to get the information about the record of a Dataverse data source.
We can check for the Read, Edit, and Delete Permission.
- RecordInfo. ReadPermission
- RecordInfo. EditPermission
- RecordInfo.DeletePermission
Hide Show control based on Security Role in Canvas App
Here for our sample Canvas App we have a button and a Gallery having Data source as Cases
1 |
Visible |
Button |
If(DataSourceInfo(Cases,DataSourceInfo.ReadPermission), true, false) |
2 |
Visible |
Edit |
If(RecordInfo(Gallery1.Selected, RecordInfo.EditPermission),true, false) |
3 |
Visible |
Delete |
If(RecordInfo(Gallery1.Selected, RecordInfo.DeletePermission),true, false) |
Now to test it, we have assigned the below custom security role/rights to another user – Test User 1 (along with Basic User security role)
i.e. Read, Write and Delete permission at the User Level on Case.
We have also shared the Average order shipment time record with Test User 1 assigning him the Write Permission.
Now when Test User 1 will open the Canvas App, the first button will be visible as he has the Read permission on the Case table.
In the gallery only the one record shared will be visible along with the Edit button on the same.
Let us just share one more case record with only Read permission to Test User 1.
We can see the record displayed for Test User 1.
It shows the Edit button for the new record, although we shared the record with the Read permission.
We have the following formula for the Edit button’s OnSelect
Patch(Cases, LookUp(Cases,’Case Number’ = lblCaseNumber.Text), {‘Case Title’:”Sample Title”})
So clicking on Edit for the new record shared ‘Complete overhaul required‘ gives the below Permission error
Now pressing the same edit button for the ‘Average order shipment time’ record will update the record (set title as Sample Title) as it was shared with Write permission with Test User 1.
Get all the details here –
https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-datasourceinfo
https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-recordinfo
Hope it helps..
It works fine for me but it seems that the result is fixed when you receive it.
Concretely, if you have a gallery of a records. Get to one specific record (when you know that your user has an EditPermission), you will retrieve “true” for the RecordInfo(ThisRecord, RecordInfo.EditPermission). After that, you remove the access of this user, the call of the function will still return “true” (even if you refresh the gallery & the datasource of the gallery). Once you relaunch the canvas app, the real value is retrieved 😕
LikeLiked by 1 person
Thanks Julien for sharing your experience !
LikeLike