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)

Default the date & time in custom field on a page

(0) ShareShare
ReportReport
Posted on by 2,911

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

I have the same question (0)
  • Suggested answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    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.

  • Alex A Profile Picture
    2,911 on at

    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!

  • Verified answer
    Suresh Kulla Profile Picture
    50,243 Super User 2025 Season 2 on at

    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
    2,911 on at

    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
    Mohana Yadav Profile Picture
    61,005 Super User 2025 Season 2 on at

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

    you need a partner license to look in to code.

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