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 :
Microsoft Dynamics NAV (Archived)

How to: Use Function in Code-unit to amount and display on Page

(0) ShareShare
ReportReport
Posted on by

I have 2 fields "Ending Date" (Date type) and "Required Arrival Day" (Integer type)

Now, I want to change "Required Arrival Day" to Date Type base on value of "Ending Date" and display on Page

I wrote a function below:

CreateRequiredArrivalDay("Required Arrival Day" : Integer;"Ending Date" : Date) RequiredArrivalDayReal : Date

//BEGIN
IF "Required Arrival Day" >= DATE2DMY("Ending Date",1) THEN
ActiveMonth := DMY2DATE(1,DATE2DMY("Ending Date",2),DATE2DMY("Ending Date",3))
ELSE
ActiveMonth := DMY2DATE(1,DATE2DMY(CALCDATE('1M',"Ending Date"),2),DATE2DMY(CALCDATE('1M',"Ending Date"),3));

CASE DATE2DMY(CALCDATE('CM',ActiveMonth),1) OF
28:
IF "Required Arrival Day" <= 28 THEN
RequiredArrivalDayReal := DMY2DATE("Required Arrival Day",DATE2DMY(ActiveMonth,2),DATE2DMY(ActiveMonth,3))
ELSE
RequiredArrivalDayReal := CALCDATE('CM',ActiveMonth);
29:
IF "Required Arrival Day" <= 29 THEN
RequiredArrivalDayReal := DMY2DATE("Required Arrival Day",DATE2DMY(ActiveMonth,2),DATE2DMY(ActiveMonth,3))
ELSE
RequiredArrivalDayReal := CALCDATE('CM',ActiveMonth);
30:
IF "Required Arrival Day" <= 30 THEN
RequiredArrivalDayReal := DMY2DATE("Required Arrival Day",DATE2DMY(ActiveMonth,2),DATE2DMY(ActiveMonth,3))
ELSE
RequiredArrivalDayReal := CALCDATE('CM',ActiveMonth);
31:
RequiredArrivalDayReal := CALCDATE('CM',ActiveMonth);
END;

EXIT(RequiredArrivalDayReal);

//END

How to use this function into page or table to display result that i want? 

Thanks!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    You can reference this function on your page (global or local variable) and use it via code (for example in OnAfterGetRecord trigger) or you can use your function as SourceExpression of a custom field of type Date that you can add on your page.

  • Community Member Profile Picture
    on at

    Stefano、

    Finally, I did it. Thank you!

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 > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans