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

Handling field errors on fields that are automatically filled

(0) ShareShare
ReportReport
Posted on by

Dear community,

I am a junior developer who is currently learning to customize business central.
For my first few extensions I noticed that a lot of the time, some sort of validation must be done on fields that are automatically filled. 2 examples of this:

1) I had a situation when choosing an item on a sales line, the quantity would automatically be set to, for example, a minimum amount.
2) when making a sales order for a certain customer, some recurring sales lines would be automatically inserted.

Now when those fields get filled up automatically, I often have some validation going on.


For example, let's say the quantity of an item on the sales line has some other conditions that must be met.
In such a case when a user fills invalid values in the field, it can give an error and it works fine. But if that field is automatically filled up, i keep having to revert the change of choosing an item.
How do I handle the difference between user input and the automatic insertion?
How do I propose a new value? I should then call validation on the proposed value as well right? To calculate other fields in the sales line? 

Anyone has some insights in this matter?
Thanks in advance.

I have the same question (0)
  • Daniel Rimmelzwaan Profile Picture
    3,485 on at

    You can use validation in code. Instead of just setting a value:

    Rec.Field := Value;

    You can use validation like this:

    Rec.Validate(Field,Value);

    This will then run the validation logic as if the user entered the field manually.

    There's another trick you can use in validation to do something only when the user is entering the value, which is the CurrFieldNo. The system keeps track which field the user is currently on, and if the validation is not run from a page object, the CurrFieldNo equals 0. Search the base app for 'CurrFieldNo' to see how you can use that

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 2,664

#2
YUN ZHU Profile Picture

YUN ZHU 960 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 773 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans