web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Validation of several fields

(0) ShareShare
ReportReport
Posted on by 555

Hi experts,

I use a Business Central wave 2 - fall 2020 on-premise.

I have made a table extension for "Purchase Line" and a page extension for "Purchase Order Subform". I have added a few new fields in those two.

I need to add some validation that depend on what item the user enter into the "No." field. So if the user enters "Item A", my validation demands that my new fields must be entered also. But if the user enters "Item B", my validation should not give an error message.

I have made my validation on the trigger "OnBeforeInsert" in the table extension. It works fine.

The problem is that if I call my validation in the trigger "OnBeforeModify", then I get the error message when the user changes "No." from "Item B" to "Item A". It says that the user has to enter values in the other fields, but the user has not moved to those fields yet. The problem must be that "OnBeforeModify" is called while the user is standing on the same record in the list page.

It is important that the user does not leave the line with bad data.

Is there another trigger/event, that I should use? (In AX there is a method that is called when a user tries to leave a record.)

Or can I see somehow what the user is doing, so that my validation is called sometimes when the "OnBeforeModify" trigger is activated, and sometimes my validation is not called?

tableextension 50103 PurchaseLine extends "Purchase Line"
{
    fields
    {
        field(50000;"My Field";Integer)
        {
            DataClassification = ToBeClassified;
            Caption = 'Some new field';
        }
    }

    trigger OnBeforeInsert()
    begin
        //ValidateMyFields();
        Message('OnBeforeInsert table');
    end;

    trigger OnAfterInsert()
    begin
        Message('OnAfterInsert table');
    end;

    trigger OnBeforeModify()
    begin
        Message('OnBeforeModify table');
        //ValidateMyFields();
    end;

    trigger OnAfterModify()
    begin
        Message('OnAfterModify table');
    end;

}

pageextension 50103 PurchaseOrderSubform extends "Purchase Order Subform"
{
    layout
    {
        addbefore("Quantity")
        {
            field("My Field"; Rec."My Field")
            {
                ApplicationArea = All;
                ToolTip = 'Something';
            }
        }
    }
}

I have the same question (0)
  • JAngle Profile Picture
    157 on at

    Why not use an onvalidate trigger on the page instead. That covers you for insert or modify in one go

  • Morten Steengaard Profile Picture
    555 on at

    I think the problem is that "modify()" is called when the user change and leave the "No." field. And therefore the user cannot fill in my new fields correctly before my validation method is called.

    I don't have an "OnValidate" trigger on the page. I only have these:

    7870.Udklip.JPG

    If I use OnModifyRecord or OnInsertRecord, that does not help me. OnInsertRecord is only triggered when the record is inserted and not when the user changes the "No." field. OnModifyRecord is called when the user leaves the "No." field and I cannot tell in my validation code, if the user just leaves the "No." field or set focus on another line or tries to close the page or anything else.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,947 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 995 Super User 2026 Season 1

#3
Teagen Boll Profile Picture

Teagen Boll 596 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans