Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

How to transfer User options from codeunit to the global function of a table via c/al code

Posted on by Microsoft Employee
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 following code works perfectly on the onValidate() function:
I realized when "Custom Toxity" = 1 this is the option for Caution
I realized when "Custom Toxity" = 2 this is the option for Danger
I realized when "Custom Toxity" = 3 this is the option for Hazardous
because the first Option is an empty option string which the system regards as 0;
IF "Custom Toxity" = 1  THEN
  "Custom Description" := 'Caution';
IF "Custom Toxity" = 2 THEN
  "Custom Number" := 6;
IF "Custom Toxity" = 3 THEN
  Commission := 99.0;
When I type it in the codeunit as the following:
LOCAL fCustomFunction(VAR updateCustomTable : Record "Custom Test")
  IF updateCustomTable."Custom Toxity" = 1  THEN
  updateCustomTable."Custom Description" := 'Caution';
  IF updateCustomTable."Custom Toxity" = 2 THEN
    updateCustomTable."Custom Number" := 6;
  IF updateCustomTable."Custom Toxity" = 3 THEN
    updateCustomTable.Commission := 99.0;

I also create a Codeunit in the in the C/AL of the Custom Test table in the Custom Toxity - OnValidate() as:
fCustomFunction.RUN(); //where fCustomFunction is of datatype Codeunit, and it is a subtype of the written codeunit
Custom Function.
The table doesn't respond to the code, even though there are no errors.

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to transfer User options from codeunit to the global function of a table via c/al code

    Thank you very much Robertas, this really helped me.

  • Suggested answer
    RobertasR Profile Picture
    RobertasR 5,002 on at
    RE: How to transfer User options from codeunit to the global function of a table via c/al code

    Hi,

    when you call codeunit (fCustomFunction.RUN), it only calls the the 'Run' trigger in the codeunit, but not your actual function 'fCustomFunction'. You have to make the function as 'global', and call fCustomFunction.fCustomFunction(Rec);

    Hope that makes sense

    Robertas

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans