Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Edit a field based on a checkbox,

Posted on by 60

Hello, 

I have a task to make a custom field editable based on a checkbox
If checkbox is checked the user can edit the specific field.

I have create a boolean variable EditCustomField, 
And in Onvalidate of the checkbox and o Onaftergetrecord (page) i have done this:

IF Edit = TRUE THEN 
EditCustomField := TRUE;

it does not wokr. 
Could you help me please?

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 73,171 Super User 2024 Season 2 on at
    RE: Edit a field based on a checkbox,

    Hi, Hope the information below can give you some hints.

    Dynamic Visibility of Controls (Hide and show fields dynamically)

    https://yzhums.com/14752/

    Switching a page to non-editable in real time via a field value

    https://yzhums.com/16756/

    Thanks.

    ZHU

  • Verified answer
    Ayala Profile Picture
    Ayala 110 on at
    RE: Edit a field based on a checkbox,

    Hello,

    I have some smaples using Enabled property, on page fields Enabled attribute you must assign EditCustomField variable, something like this:

                   field("Warning 1"; Rec."Warning 1")

                   {

                       Enabled = EditCustomField;

                       ApplicationArea = All;

                   }

    Using Enabled must works too, I have created this sample page and it works:

    page 60000 TestPage

    {

       PageType = Card;

       ApplicationArea = All;

       UsageCategory = Administration;

       SourceTable = Integer;

       SourceTableTemporary = true;

       SourceTableView = where(Number = Const(1));

       Editable = true;

       layout

       {

           area(Content)

           {

               group(GroupName)

               {

                   field(SearchString1; SearchString1)

                   {

                       ApplicationArea = All;

                       Editable = CanEdit2;

                   }

                   field(SearchString2; SearchString2)

                   {

                       ApplicationArea = All;

                       Editable = CanEdit2;

                   }

                   field(ItemEntry; ItemEntry)

                   {

                       ApplicationArea = All;

                       Editable = CanEdit2;

                   }

                   field(CanEdit; CanEdit)

                   {

                       ApplicationArea = All;

                       trigger OnValidate()

                       begin

                           CanEdit2 := CanEdit;

                       end;

                   }

               }

           }

       }

       var

           SearchString1: Text;

           SearchString2: Text;

           CanEdit: Boolean;

           CanEdit2: Boolean;

       trigger OnOpenPage()

       begin

           CanEdit := true;

           CanEdit2 := true;

       end;

    }

    Is not necessary to have two boolean variables, with one only CanEdit you can avoid OnValidate code.

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,125 Super User 2024 Season 2 on at
    RE: Edit a field based on a checkbox,

    can you paste all your code?

    Did you assign the variable to the editable property of the custom field?

    Is there any reason why you want to do it as editable only?

    You can also simply write code under custom field onvalidate to check the boolean field

    TESTFIELD(boolean,true);

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 229,993 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans