This is a short note on how to add further validation to the sales or purchase document lines in Dynamics 365 Business Central with a small AL code extension.
There are a number of validations operating in the background for sales and purchase lines. Sometimes you need to add to this, in this example I'll build a small app to meet the following requirement.
- Prevent sales lines with zero value
This is a great starting point for building apps https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-get-started
To meet this requirement I'll use the OnAfterInsert trigger which will carry out the checks after the system already validated at the database level.
Here is the example code:
What if we want more? I asked to validate in a different way: "Please rewrite the code to also prevent the job and job task from being blank"
Looks good, I liked the way it also updated the error message, very handy. Would need testing of course.
The original simple .app and code can be found here https://github.com/andywingate/d365bc-validatesalesline