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...
Answered

Create mandatory field

(0) ShareShare
ReportReport
Posted on by 555

Hi experts,

I would like to create a mandatory field on the table "Shipping Agent". It is an integer.

If I write my validation code in the OnInsert trigger on the table extension, it is too soon. When the user leaves the first field, it is validating the field that the user hasn't come to yet. That doesn't work.

If I write my validation code in the OnModify trigger on the table extension, it is not executed if the user simply enter a value in the first field and then leave the record. That doesn't work either.

I have another table, that I have created in my app. That table has a page, where I have set "DelayedInsert = true". That works, but I cannot set this in a page extension, but only directly on the page.

How do I make a simple and secure mandatory field, so that it is impossible for the user to create a record with zero in my integer field?

I have the same question (0)
  • Nitin Verma Profile Picture
    21,698 Moderator on at

    Hi,

    Go to that Page and write your code on OnQueryClosePage trigger, I hope it will solve your problem

    Thanks.

  • Morten Steengaard Profile Picture
    555 on at

    Hi Nitin,

    Thank you for your reply.

    I think that would work if the page was a card page, but in this case it is a list page. So I can create a lot of bad records, before OnQueryClosePage is triggered.

    (Of course, I can write some code in that trigger telling the user that one or more records are wrong and must be changed, before the page can be closed, but that is not a beautiful solution.)

  • Amit Baru Profile Picture
    3,037 on at

    Hi,

    Write code on "OnQueryClose" trigger.

    Regards

    Amit Sharma

    www.erpconsultors.com

  • Nitin Verma Profile Picture
    21,698 Moderator on at

    Ok,

    Try to subscribe the Event of that table "OnBeforeInsert" and then check

    Thanks.

  • Morten Steengaard Profile Picture
    555 on at

    Now, I have made this in a codeunit:

       [EventSubscriber(ObjectType::Table, Database::"Shipping Agent", 'OnBeforeInsertEvent', '', true, true)]

       local procedure MyProcedure(var Rec: record "Shipping Agent"; RunTrigger: Boolean)

       begin

           Message('event...');

       end;

    It is called when the user leaves the first field ("Code"). That didn't do the trick.

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    Do the yellow changes.

    [EventSubscriber(ObjectType::Table, Database::"Shipping Agent", 'OnBeforeInsertEvent', '', true, true)]

      local procedure MyProcedure(var Rec: record "Shipping Agent"; RunTrigger: Boolean)

      begin

          Error('event...');

      end;

  • Morten Steengaard Profile Picture
    555 on at

    It is still called at the wrong time.

    When the user enters something in the first field ("Code") and leaves that field, then it should not give an error telling the user that my field has no value. The user has not reached to my field yet.

    The error message must come when the user has had the chance to enter a value in my field, but did not do it.

    I have a feeling, that it is not possible in Business Central.

  • Suggested answer
    Nitin Verma Profile Picture
    21,698 Moderator on at

    try with event

    [EventSubscriber(ObjectType::Table, Database::Yourtable, 'OnAfterModifyEvent', '', false, false)]

  • Morten Steengaard Profile Picture
    555 on at

    That didn't work either :-(

    With this code I can create a record with a value in the field "Code" and no value in my mandatory field.

  • YUN ZHU Profile Picture
    95,329 Super User 2025 Season 2 on at

    Hi, hope the following helps as well.

    https://yzhums.com/4940/

    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,229

#2
Jainam M. Kothari Profile Picture

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

#3
YUN ZHU Profile Picture

YUN ZHU 1,153 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans