Using DataSourceInfo and RecordInfo function for checking permissions for a Dataverse table or record in Canvas App


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..

Advertisements

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

One thought on “Using DataSourceInfo and RecordInfo function for checking permissions for a Dataverse table or record in Canvas App”

Please share your thoughts

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.