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

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Change hundreds field visibility and caption dynamically by code

(1) ShareShare
ReportReport
Posted on by

Dear friends,

I am creating a page with around 400 fields, and 300 fields of them should change the visibility and caption dynamically according to the user setup record from set up table.

My requirement is to set the visibility and caption of 300 fields in code C/AL dynamically. As far as I know, I can set a boolean variable as visible property for fields. But what about caption? Also, as I have so much fields, can I simplified the process by some code like below

_FieldControl.visible(false);

_FieldControl.caption('ABC');

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Change hundreds field visibility and caption dynamically by code

    To dynamically change caption, you can create a function ChangeCaption that is eventsubscriber of Codeunit ApplicationManagement, event OnAfterCaptionClassTranslate.

    The signature of your function will be:

    LOCAL [EventSubscriber] ChangeCaption(Language : Integer;CaptionExpression : Text[1024];VAR Caption : Text[1024])

    where CaptionExpression is the caption of your field (like in the table) and Caption is the caption that you want to set.

  • Community Member Profile Picture
    on at
    RE: Change hundreds field visibility and caption dynamically by code

    Thanks Stefano, and do you have any idea about  visible property for hundreds of fields?

  • Community Member Profile Picture
    on at
    RE: Change hundreds field visibility and caption dynamically by code

    Hi Stefano, I think you may misunderstand my problem. My problem is not how to trigger the caption and visible property change, but is how to change them by code.

    Actually I have two question,

    1. How to change visible and caption property by C/AL code, do sth like below ?

    _FieldControl.visible(false);

    _FieldControl.caption('ABC');

    2. As I have hundreds of field need to do so, can I have an efficient loop to achieve my requirement?

    Thanks a lot.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Change hundreds field visibility and caption dynamically by code

    Can you group those users in some roles?

    Maybe it is eraser to make a page for every role and give permission for it only for that role.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Change hundreds field visibility and caption dynamically by code

    The event described is triggered when the page renders the field caption, so here you can place the code you want to change the caption. For example, you can check the field ID and change the caption accordingly (I don't know your requirements for this logic). So, if your page has 1000 fields, you can check the field ID and change is caption accordingly.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Change hundreds field visibility and caption dynamically by code

    400 fields, a lot of records and such trigger will slow down the page viewing time a lot.

    If users will make some filters too (and if there are many ... users I mean) I don't see this solution too responsive.

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Change hundreds field visibility and caption dynamically by code

    CAPTIONCLASS or this event is the way you have in NAV.

    Check here, maybe it could be helpful:

    gaspodethewonderdog.blogspot.it/.../field-captions-and-captionclass.html

  • Community Member Profile Picture
    on at
    RE: Change hundreds field visibility and caption dynamically by code

    Thanks Stefano, following your suggestion the caption problem is solved by set the field Captionclass property to sth like '1,5,,' + GetItemName(C_1).

    But unfortunately, when I try to do the same thing for field property visible(set as a boolean function GetItemVisibility(C_1)), a error will pop to said "unknown function type". So does it mean I can only use variable rather than function to dynamically set the visible property?

    As I have multiple fields, it is not possible to set the variable value one by one like below

    If C_1Rec.Display=true then

    C_1Visible:=true;

    Else if C_2Rec.Display=true then

    C_2Visible:=true;

    I would like to use function to dynamically return boolean value or do you have any other advise? Thanks a lot!

  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at
    RE: Change hundreds field visibility and caption dynamically by code

    For visibility, you need to set the Visible property of your fields to a boolean variable (for example IsField1Visible and so on). Then, setting this variable to true of false in code does what you want to obtain (field visible or not accordingly to the variable's value).

    You cannot loop through controls in a page, so this is the unique way.

  • Community Member Profile Picture
    on at
    RE: Change hundreds field visibility and caption dynamically by code

    OK, then l am thinking whether it is possible to assign the variable value by a way like this?

    Declare my boolean variable as C_1Visible;

    Text 60: ItemName:='C_1';

    SetVariableValueByName(ItemName+'Visible', TRUE);  //Set the variable value by the variable name

    In this way I can use loop to assign the variable value... Thanks!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Saurav.Dhyani Profile Picture

Saurav.Dhyani 2 Super User 2025 Season 2

#2
RK-25090803-0 Profile Picture

RK-25090803-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans