Microsoft Power Apps

Control access with RecordInfo and DataSourceInfo in Power Apps

When you create apps, you might find that different users get different things to do. With RecordInfo and DataSourceInfo you can control elements in your app by using Dataverse permissions

DataSourceInfo

When you use a table in Dataverse that a user doesn’t have access to you might get these error messsages:

You don’t have access to view this data. Server Response <Tablename> failed.

The message is clear, the user hasn’t been given access to a table that the app needs to read.

Now you could create a user role with some permissions on the table and the error message will go away. But what if, the user shouldn’t have access to this table and you want the app to behave differently for different types of users.

You could end up with many apps different apps, or you could handle this using the DatasourceInfo function.

In my case I’ve got a gallery that displays my fruit from my table. Using the following line, I can check if the user has read access to the table.

If(DataSourceInfo(Fruits,DataSourceInfo.ReadPermission), Fruits)

Now when the user doesn't have access to the table no error will be thrown.

RecordInfo

Whereas DatasourceInfo works on the full table, sometimes you might want to use similar tricks on a record by record basis.

Potentially, you could accomplish the delete button using somethign like:

If(DataSourceInfo(Fruits,DataSourceInfo.DeletePermission), Fruits)

However, you might sometimes have different permissions configured at a record level.

This is where the RecordInfo Function comes in and something like this on the Visibility property would then work.

RecordInfo(ThisItem, RecordInfo.DeletePermission)

Quite often you will find that delete permissions are set at a table level but it is not uncommon to have edit permissions set at a record level. That way you could change the Edit button into a View button like this:

If(RecordInfo(ThisItem, RecordInfo.EditPermission),”Edit”, “View”)

General thoughts

I’ve seen quite a few apps that have their own role based security baked into the app, but if you can use RecordInfo and DatasourceInfo instead then you can take all that security complexity work away from your app and place it where it belongs, in your data model.

One limitation, however, the two functions described in this post, only work with Dataverse. Hopefully this will support SharePoint lists as well one day.

You could also use this to check if a developer or another user is logged in, by checking access on the solutions table. Then you could hide all those little debug options that you may add as a developer.

Share
Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

View Comments

Recent Posts

3 steps to implementing a better date picker in Power Apps

One of the biggest annoyances of Canvas Apps in Power apps is the date picker.…

3 days ago

Power Automate Flow run failed: Connection not configured for this service

Today I was battling with the Connection not configured for this service error. Background Iv'e…

3 weeks ago

Open Word documents in the desktop app from Power Apps

When you open Word documents from Power Apps you might have noticed that Word Online…

2 months ago

Introducing Portal Apps in Power Apps

Power Apps has three types of apps. One of them is the Portal app. In…

2 months ago

NEVER give your SharePoint fields the displayname of Value!

After an hour of banging my head against a brick wall when my Patch command…

2 months ago

Collect flow runs of your failed child flows

When you use child flows, you might need to collect the flow runs of your…

2 months ago