The work date is an essential part of the NAV system. This recipe will show you how to determine what that date is, as well as when and where you should use it.
The work date is a date internal to the NAV system. This date is returned using the WORKDATE
keyword. It can be changed at any time by going to Tools | Work Date.
It is important to understand the difference between the NAV work date and the computer system date. They should be used in specific circumstances. When performing general work in the system, you should almost always use the WORKDATE
keyword. In cases where you need to log information and the exact date or time when an action occurred, you should use TODAY
and TIME
or CURRENTDATETIME
.
The following code can be found in table 36, Sales Header, in the InitRecord()
method:
IF "Document Type" IN ["Document Type"::Order,"Document Type"::Invoice,"Document Type"::Quote] THEN BEGIN methodInitRecord()"Shipment Date" := WORKDATE; "Order Date" := WORKDATE; END; IF "Document Type" = "Document Type"::"Return Order" THEN "Order Date" := WORKDATE; IF NOT ("Document Type" IN ["Document Type"::"Blanket Order","Document Type"::Quote]) AND ("Posting Date" = 0D) THEN "Posting Date" := WORKDATE; IF SalesSetup."Default Posting Date" = SalesSetup."Default Posting Date"::"No Date" THEN "Posting Date" := 0D; "Document Date" := WORKDATE;
It is common to create and call an InitRecord()
method from a table's OnInsert
trigger especially for document-style tables. Unlike with the InitValue
property for fields in a table, fields here are filled in based on conditional logic. More importantly, validation can be performed to ensure data integrity.
Looking at this snippet of code, we can see that every date is filled in using the WORKDATE
keyword, and not using TODAY
. This is so that a user can easily create records that are pre-dated or post-dated.