web
You’re offline. This is a read only version of the page.
close
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? 

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    95,595 Super User 2025 Season 2 on at

    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

  • Maxim Rylev Profile Picture
    75 on at

    Than you for your reply.

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

  • Suggested answer
    Mohana Yadav Profile Picture
    61,001 Super User 2025 Season 2 on at

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

  • Maxim Rylev Profile Picture
    75 on at

    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
    61,001 Super User 2025 Season 2 on at

    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.

  • Suggested answer
    YUN ZHU Profile Picture
    95,595 Super User 2025 Season 2 on at

    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

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,010

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,270 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,085 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans