Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Change hundreds field visibility and caption dynamically by code

(1) ShareShare
ReportReport
Posted on by Microsoft Employee

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

  • RE: Change hundreds field visibility and caption dynamically by code

    Hi Andre

    How can you split the balance by transaction currency on a main account in Management Reporter 

  • Community Member Profile Picture
    Community Member Microsoft Employee 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!

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 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
    Community Member Microsoft Employee 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
    Stefano Demiliani 37,162 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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee 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
    Stefano Demiliani 37,162 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
    Community Member Microsoft Employee 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.

  • Community Member Profile Picture
    Community Member Microsoft Employee 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.

  • Community Member Profile Picture
    Community Member Microsoft Employee 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?

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans