Hi all,
I have a table called custom table with 7 fields:
- Custom Code datatype: Code;
- Custom Picture datatype: BLOB;
- Expiry Date of type: Date;
- Toxity of type option the options are: , Caution, Danger, and Hazardous;
- Custom Number of datatype: integer;
- Custom Description of type: text and
- Commission of type decimal.
I need to write a codeunit that will be called in the C/AL of the custom table that will transfer user options to the C/AL code.
From the option list the code works perfectly on the onValidate() function:
0
Comments
but when implemented on the codeunit it does not work.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
For example, the codeunit should:
1. When the user chooses the option 'Caution' on the option list the text Caution should be added to the Custom Description field.
2. When the user chooses the option 'Danger' on the option list the Custom Number should be changed to 6.
3. When the user chooses the option 'Hazardous' on the option list the commission field should be changed to 99.
Anyway - the codeunit can have a table as a parameter. You can pass your rec (your custom table) to the codeunit call in Toxity - OnValidate, like this Then inside the codeunit's OnRun trigger you can have your code changing values in your custom table (the one passed in CODEUNIT.RUN call:
I hope this answers your question. Not sure why do you need to have this in a separate codeunit, and why having the code in the Toxity - OnValidate trigger is not good enough. The only purpose I can think of is add flexilbility and enable different classification by specifying different codeunit ID to be run from Toxity - OnValidate in some setup, and that those codeunits will be added to your solution at later stages.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
I had initially put the validation rules in the Toxity - OnValidate trigger and it worked very well.
But I was informed that they prefered for the OnValidate trigger to have less code and to populate the code and validation rules on a Codeunit instead.
I am really grateful.
My 0.01£
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Instead of CODEUNIT.RUN, just call that NewCodeUnit.DoThisFunction.
Putting it in a separate codeunit, makes it easier to maintain and update in the future.
Just a happy frood who knows where his towel is
Why spreading given functionality between two objects, rather than having it all in one place, would make it easier to maintain and update in the future?
How about user access management, does managing user permission for two separate objects also make it easier than having to manage the permissions for the table alone?
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
It also depends on the requirement and personal preferences. Sometimes it makes sense to put simple codes in one place. However, I found out that normally we can always reuse the functionality elsewhere, so it is easier to maintain it if we have a separate codeunit (instead of putting it on the OnValidate).
Also when working with multiple developer, it is easier to spot and merge objects.
Just a happy frood who knows where his towel is
Where as if this was in a table, I would have to restart all the services, and users would get those error messages "The Definition of table blah blah has changed".