Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Update field value after change other fields value

(0) ShareShare
ReportReport
Posted on by 75

Hi. In one of setup tables I created my new custom field. This field depends on value of five other fields - all these field must be 'true' if value of my custom field also can be 'true'.

So when user set 'false' value of one of these five fields - my custom field should change value to 'false'.

What is the most optimal way to achieve this?

Trigger OnModify() inside table? OnAfterModify Event Subcsriber in separate CodeUnit? Or maybe any other idea? 

  • Suggested answer
    YUN ZHU Profile Picture
    79,380 Super User 2025 Season 1 on at
    RE: Update field value after change other fields value

    In addition to the codeunit mentioned by Mohana, you can also use tableextension directly.

    For example,

    pastedimage1668494495678v1.png

    If you want to change immediately, I recommend adding each field.
    Or you consider enabling the following functions.

    Business Central 2022 wave 2 (BC21) new features: Auto-save as you work -> Trigger timing of OnModify (Table) Trigger/OnModifyRecord (Page) Trigger has changed

    https://yzhums.com/30730/

    Hope this helps.

    Thanks.

    ZHU

  • Suggested answer
    Mohana Yadav Profile Picture
    60,199 Super User 2025 Season 1 on at
    RE: Update field value after change other fields value

    If you want that code to be executed after modifying all fields then OnAfterModify trigger.

    Otherwise, you can create a function and call the function in each field OnAfterValidate trigger.

  • Maxim Rylev Profile Picture
    75 on at
    RE: Update field value after change other fields value

    But in situation when I need check five fields - more optimal is create 5 subscribers to OnAfterValisate triggers or maybe one subscriber to OnAfterModify?

  • Suggested answer
    Mohana Yadav Profile Picture
    60,199 Super User 2025 Season 1 on at
    RE: Update field value after change other fields value

    You have to subscribe to OnAfterValidate trigger of the field in a codeunit.

  • Maxim Rylev Profile Picture
    75 on at
    RE: Update field value after change other fields value

    Than you for your reply.

    But what if the fields are standard fields? And I cant use On Validate triggers?

  • Suggested answer
    YUN ZHU Profile Picture
    79,380 Super User 2025 Season 1 on at
    RE: Update field value after change other fields value

    Hi, If I understand correctly, it's simple to do with OnValidate Trigger.

    For example,

    table 50112 MyTable2
    {
        DataClassification = CustomerContent;
    
        fields
        {
            field(1; MyField; Integer)
            {
                DataClassification = CustomerContent;
            }
            field(2; A; Boolean)
            {
                DataClassification = CustomerContent;
    
                trigger OnValidate()
                begin
                    if A = false then
                        CustomField := false;
                end;
            }
            field(3; B; Boolean)
            {
                DataClassification = CustomerContent;
    
                trigger OnValidate()
                begin
                    if B = false then
                        CustomField := false;
                end;
            }
            field(4; C; Boolean)
            {
                DataClassification = CustomerContent;
    
                trigger OnValidate()
                begin
                    if C = false then
                        CustomField := false;
                end;
            }
            field(5; D; Boolean)
            {
                DataClassification = CustomerContent;
    
                trigger OnValidate()
                begin
                    if D = false then
                        CustomField := false;
                end;
            }
            field(6; E; Boolean)
            {
                DataClassification = CustomerContent;
    
                trigger OnValidate()
                begin
                    if E = false then
                        CustomField := false;
                end;
            }
            field(7; CustomField; Boolean)
            {
                DataClassification = CustomerContent;
    
                trigger OnValidate()
                begin
                    if CustomField = true then begin
                        A := true;
                        B := true;
                        C := true;
                        D := true;
                        E := true;
                    end;
                end;
            }
        }
    }

    PS: You can replace "If Boolean = true then" and "If Boolean = false then" with "If Boolean then" and "If not Boolean then".

    Hope this helps.
    Thanks.

    ZHU

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,280 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,038 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans