Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Default the date & time in custom field on a page

Posted on by 2,348

In our test environment, I have added a custom field on our Sales Order form called 'Date/Time Received' where the user entering Sales Orders can set the date and time that the order came in.

I have already added the column in the table (table 36: datatype = datetime) and the field on the Sales Order form (page 42: the element on the form holds date and time). It looks good and works perfectly. However, what I need to be able to do is have this field on the Sales Order default to the current date and time as soon as a new Sales Order is created. If someone could please explain where to put the code and how I can do that I would greatly appreciate it.

*This post is locked for comments

  • Verified answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,139 Super User 2024 Season 2 on at
    RE: Default the date & time in custom field on a page

    yes, it seems you didn't have proper license.

    you need a partner license to look in to code.

  • Alex A Profile Picture
    Alex A 2,348 on at
    RE: Default the date & time in custom field on a page

    Ahh man I'm bummed. When I select the design of table 36 and go to the View drop down menu, the option for 'C/AL Code' is grayed out and I cannot choose it; if I press F9 nothing happens too. Man I wonder if this is because I don't have the right developers license for this or if I'm missing something else :(

    Either way, Suresh I really appreciate your time. I'll have to try to figure out why I can't get into the code for this table.

  • Verified answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Default the date & time in custom field on a page

    From the development environment select design of the table 36, and then press F9 (View -> C/AL Code)

    In the code window go to the top, you will see after Documentation trigger, OnInsert Trigger in that you will see already there is some code and a line InitRecord function being called click on that line and right click use Go-to Definition

    The cursor will be in the InitRecord function, in that you will see a line where

    "Document Date" :=  WORKDATE;   after that line add your code in your case if the field name is A

    A := CURRENTDATETIME;

    File - > Save , File -> Exit.

  • Alex A Profile Picture
    Alex A 2,348 on at
    RE: Default the date & time in custom field on a page

    Thank you Suresh; you're the man. I'm going to need some step by step instructions. I'm in the NAV Dev Environment, in Design of table 36, and I have the line for my custom field highlighted... which menu option do I start with? I am a developer but still learning NAV development. Where do I find the OnInsert Trigger? And if anyone can supply the code example that would be great!

  • Suggested answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Default the date & time in custom field on a page

    You need to add the code in the OnInsert Trigger of the table 36, there is a function called InitRecord which is called in that trigger,  you can go that function and initialize your field.  In the same function all other date fields are also defaulted.

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