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 :
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? 

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    90,181 Super User 2025 Season 2 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,635 Super User 2025 Season 2 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,635 Super User 2025 Season 2 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
    90,181 Super User 2025 Season 2 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

Responsible AI policies

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

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sumit Singh Profile Picture

Sumit Singh 2,708

#2
Sohail Ahmed Profile Picture

Sohail Ahmed 2,675 Super User 2025 Season 2

#3
Jeffrey Bulanadi Profile Picture

Jeffrey Bulanadi 2,203

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans