Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

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

Posted on by Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to: Use Function in Code-unit to amount and display on Page

    Stefano、

    Finally, I did it. Thank you!

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: How to: Use Function in Code-unit to amount and display on Page

    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.

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans