In this blog post, we will learn to check logged-in user privileges & column metadata for a Data Source in Canvas App. Before we start, make sure to subscribe to CRM Crate so that you can stay up to date in the field of Power Platform.
Canvas apps are powerful tools that allow users to create custom applications tailored to their specific needs. One crucial aspect of app development is ensuring secure access to data sources while maintaining a seamless user experience. In this blog, we’ll explore the essential steps to check the logged-in user’s privileges on a data source within a canvas app.
Using DataSourceInfo function for fetching column-level & source-level information
Harnessing the insights from data sources can greatly enhance the overall user experience. Leveraging column-level details allows you to validate user input effectively, offering instant feedback through functions like Patch and Validate.
You can also tap into data-source-level information. For example, you have the ability to disable or conceal Edit and New buttons for users lacking the necessary permissions / privileges to create or edit table rows. This ensures a more controlled and secure user interface in your Canvas App. Use the below Power FX function for fetching column-level and source-level information from your data source.
DataSourceInfo( DataSource, InformationType, ColumnName )
DataSource – This is a required parameter and should contain the data source object such as Table.
Information – This is a required parameter and should contain the type of information you wish to retrieve from your data source.
ColumnName – This is an optional parameter. For column-level information, the column name as a string. Column Phone would be passed as “Phone”, including the double quotes. For information at the data-source level, the ColumnName argument can’t be used.
Getting logged-in user privileges in Canvas App using DataSourceInfo() function.
The following are the different type of operations you can perform to retrieve the privileges of the logged-in user using the DataSourceInfo function.
DataSourceInfo.CreatePermission
This function will return a Boolean result determining if the current user have permission to create records in this data source.
DataSourceInfo( crmcrateDataSource, DataSourceInfo.CreatePermission)
DataSourceInfo.DeletePermission
This function will return a Boolean result determining if the current user have permission to delete records in this data source.
DataSourceInfo( crmcrateDataSource, DataSourceInfo.DeletePermission)
DataSourceInfo.EditPermission
This function will return a Boolean result determining if the current user have permission to edit or update records in this data source.
DataSourceInfo( crmcrateDataSource, DataSourceInfo.EditPermission)
DataSourceInfo.ReadPermission
This function will return a Boolean result determining if the current user have permission to read or view records in this data source.
DataSourceInfo( crmcrateDataSource, DataSourceInfo.ViewPermission)
Getting column-level information of a data source using DataSourceInfo() function.
The following are the different type of operations you can perform to retrieve the column-level information of a data source using the DataSourceInfo function.
DataSourceInfo.DisplayName
This function will return a string result of the display name for the column. If no display name is defined, returns the column name.
DataSourceInfo( crmcrateDataSource, DataSourceInfo.DisplayName, "cc_name" )
DataSourceInfo.MaxLength
This function will return a numeric result of maximum number of characters that the column can hold. This function is applied only to columns that contain strings. If a maximum isn’t set, returns blank.
DataSourceInfo( crmcrateDataSource, DataSourceInfo.MaxLength, "cc_name" )
DataSourceInfo.MaxValue
This function will return a numeric result of maximum numeric value that a column can hold. This function is applied only to columns that contain numbers. If a maximum isn’t set, returns blank.
DataSourceInfo( crmcrateDataSource, DataSourceInfo.MaxValue, "cc_count" )
DataSourceInfo.MinValue
This function will return a numeric result of minimum numeric value that a column can hold. This function is applied only to columns that contain numbers. If a minimum isn’t set, returns blank.
DataSourceInfo( crmcrateDataSource, DataSourceInfo.MinValue, "cc_count" )
DataSourceInfo.Required
This function will return a Boolean result as true is the column needs a mandatory non-empty value and returns false vice versa.
DataSourceInfo( crmcrateDataSource, DataSourceInfo.Required, "cc_name" )
The below animations illustrates the working on DataSourceInfo() Power FX function in Canvas App.
In conclusion, the DataSourceInfo
function stands out as a valuable tool within the canvas app developer’s toolkit, providing crucial insights into the characteristics and capabilities of data sources. By leveraging this function, developers can dynamically adapt their applications to varying data source conditions, empowering them to create more responsive, flexible, and user-friendly experiences.
Great article. Thanks CRM Crate