Financial reporting folders access to the specific users X++
Hi folks,
This blog will be useful in those scenarios where in form datasource OnQueryExecuting event handler can be implemented for applying a range to filter the data on the standard Microsoft form.
Requirement:
Recently, I came across a requirement where I had to filter the Financial reporting folders on standard Microsoft shared Financial reporting form for specific users due to security. This can be achieved using Microsoft standard record level security framework and that requires some minor customization along with users security configuration which is assignment of record level security roles to the users that Business process owners didn't want as they wanted to control the access from their end. Since, Business process owners for the specific company can only decide to whom Management report folder access can be granted and not the System administrators therefore a custom simple list page form was developed on which Business process owners was granted access so that they can handle the security access to the Financial reporting folders as per their requirements.
Solution:
Below minor customization can be done to fulfill business requirements related to Financial reporting folders access to the specific users.
1) Create a shared table named "MRReportAccess" that contains below two fields:
a) Field type: String
Name: User Id
Extended data type: UserId
b) Field type: String
Name: Folder
Extended data type: FinancialReportFolder
2) Create a simple list details form and attach "MRReportAccess" datasource to the grid and then add two fields "UserId" and "Folder" on the grid.
3) Create an Event handler class as below
public class D365MRReportAccess
{
/// <summary>
/// This method is used to restrict user for accessing specific MR reports
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormDataSourceEventHandler(formDataSourceStr(FinancialReports, FinancialReports), FormDataSourceEventType::QueryExecuting)]
public static void FinancialReports_OnQueryExecuting(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun financialReports = sender.formRun();
MRReportAccess reportAccess;
container reportfolderName;
while select reportAccess
where reportAccess.UserId == curUserId()
{
reportfolderName += queryValue(reportAccess.Folder);
}
if(conLen(reportfolderName) != 0)
{
sender.query().dataSourceName(sender.name()).addRange(fieldnum(financialReports,Folder)).value(con2str(reportfolderName));
sender.query().dataSourceName(sender.name()).addRange(fieldnum(financialReports,Folder)).status(RangeStatus::Locked);
}
}
}

Like
Report
*This post is locked for comments