Data Validation, you're doing it wrong! with AL in Business Central

preview_player
Показать описание
Well, not you of course, but everyone else is doing it wrong :)

Рекомендации по теме
Комментарии
Автор

More beginner type videos like this please! Great content to learn from when doing app dev for BC

jackpeterson
Автор

i think that the message could be - know the "base" - then you can decide whether to validate or not (and when not validating, live with the "consequences") - but you are right, better validate than fill all the missing stuff later (or worser - forget to fill it)

stephanweikelt
Автор

Another great topic!
Looking at the field order on the Page/Form was the way I learned how to fill out GenJournalLines and other "tricky" records like that :)

There is ONE case, where I'm in a little conflict with myself... Should I validate fields that are copied from another record?
I.e. I validated "Customer No." which should then fill in 'Customer Name'... Should I validate or copy 'Customer Name'. I kind of expect the interesting things to happen at 'Customer No.'.
Right now I am validating, but even from 'Base Application' I see them copy in cases like this.

Pharrious
Автор

Thanks for your effort Erik, you've helped me overcome some hard situations!

I have one question about this topic. What would be the best place to trigger validates in if a user makes a change in a record using the GUI? Inside the Table or in the Page?
Cheers!

alfonsovargasitcon
Автор

From the database perspective, how insert/modify pattern is better than just insert after you validate all the fields? You have to call two triggers Instead of one which is slower.

mateuszdygas
Автор

Is there known name for pattern that you describe (init, insert, modify), or how do you call it?

stefantomasevic
Автор

Thanks!.. now I have to re-write some of my bad coding.. :-)

plymouthfop
Автор

The best extension citizen in the World!

nemanjavelickovic
Автор

Looking at the code from this video, it screams to me that there is a problem with not validating your data before inserting a record.
You are doing the SH.Insert before you have validated that you have good data in the rest of the fields.
Why would you want a sales header which does not have a sell-to customer or other (what I would think are) required fields?

I know in your video, you're doing Validate triggers and a modify immediately after the insert, but there's nothing that requires you to do that.
I could conceivably programmatically insert a record with only primary key fields, and nothing in other business-required fields


I found a problem with your UI example of adding a new customer on the CRONUS database.
I click new, choose a template, and immediately click the Back button on the page.
The customer record has been saved, but there is no name on it (which is a required field), no tax area code (which is a required field), and nothing at all in any other fields.
I would expect it to stop me from closing the page, either telling me to fill in required fields, or telling me to cancel the add of the record.


If I was doing this programmatically, there would need to be some exception handling, throwing an error if required fields were not populated
Something to the effect of
if not Mytable.Insert(true) then
error('Insert did not succeed');
This is assuming that the Mytable.Insert(true) would return False if a required field was not populated. That may be an incorrect assumption in Business Central.

I am on version 18.5.29545

williamyater
Автор

Validation should be done at doc level, not record/field level. (in business apps I mean, doc oriented by definition). Just an old consultant opinion, struggling in the field with confused end-users about circular validations and stuff.

eugeni.
Автор

click bait indeed, coz i went to the school of Erik :)

BusinessCentralMusings