web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Role-Based Field Visibility in Report

(0) ShareShare
ReportReport
Posted on by 72

Hello Community,

I need to make the amount-related fields in the report visible or hidden based on the security role.

So, I have created the Security Role and written code for it. Then, I created a custom field in the InventAgingTmp table to connect the X++ code to the report fields (as a bridge), wrote the security role code, and added the expression to the column visibility expression. One main point is that this project was done by someone else; that is, this project was already existed, and I have just started working from creating the role.   The following are the details:

/// <summary>
/// Extension of InventAgingDP class
/// </summary>
[ExtensionOf(classStr(InventAgingDP))]
final class InventoryAgingDP_Extension
{
   public InventAgingContract contract;
   public InventAgingTmp  temp;
   public InventAgingTmp      tmp;

   /// <summary>
   /// COC is used for the run method to insert AsonDate value
   /// </summary>
   protected void run()
   {
       delete_from temp;
       contract = this.parmDataContract();

       temp.TPZ_AsOnDate     = contract.parmAsOnDate();
       temp.TPZ_ReportingCur = contract.parmreportingCur();

       next run();
   }

   //My code 
   public static boolean hasAmountRole()
   {
       SecurityRole     securityRole;
       SecurityUserRole securityUserRole;

       select firstonly Name from securityRole
           exists join securityUserRole
           where securityRole.RecId == securityUserRole.SecurityRole
           && (securityRole.Name == 'InventAgingValueFieldsRole'
           || securityRole.Name == "Current User")
           && securityUserRole.User == curUserId();

       return securityUserRole.RecId != 0;
   }

}   
[ExtensionOf(tableStr(InventAgingTmp))]
final class InventAgingTmp_Extension
{
   public void insert()
   {
       this.ShowAmount = InventAgingDP::hasAmountRole() ? NoYes::Yes : NoYes::No;
       next insert();
   }
}  
The expression used in the column visibility property - show or hide based on the expression is:

=IIF(Fields!TPZ_ShowAmountLabel.Value = 1, false, true)
The actual problem is that if I add this expression, either I add the role to the user or not the column gets hidden. Where, when the role is assigned the columns should be Visible. So, may I know what is the reason the field is not getting visible? 

Categories:
  • Martin Dráb Profile Picture
    240,738 Most Valuable Professional on at

    Moved from Integration, Dataverse, and general topics forum to Finance | Project Operations, Human Resources, AX, GP, SL forum.

     

    An obvious problem that you refer to TPZ_ShowAmountLabel in your expression, but you never set any value to this field in your code. You probably intended to do it in insert().

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 415 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 374

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 365 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans