This seems to be the week for guest blogging, I wrote a post for the NAV team blog about database collations.
One of the oldest features in C/AL and the AL code before that is the TODAY function. It will return the current date from the local computer.
A close friend of TODAY is WORKINGDATE. Working Date is the concept of setting “today” to be something else.
When working with entering data, the ease of type t in a date field for today, and w for working date are good for entering data.
But what about when you’re using TODAY (or WORKINGDATE) in your code?
Yesterday I came across an example in one of our old products:
IF CALCDATE('CM+1D',DueDate) > TODAY THEN PostSomething() ELSE PostSomethingElse();
Depending on the current date when the user pressed Post, different things would be posted.
It got me thinking, when is the use of TODAY appropriate in code?
The first valid use case would be to add a timestamp to records, field like “Modified Date, “Created Date”, “Approved Date”. Fields where you are recording the date of a user action.
In most other cases, you should use WORKINGDATE to give your users a chance to control the flow. And if actions in your code depend on Dates – let the user know about this.
Do you have other examples of the bad or good use of TODAY?
Grap ’em while there are hot 🙂
- Microsoft Dynamics NAV 2017 CU 3
- Microsoft Dynamics NAV 2016 CU 16
- Microsoft Dynamics NAV 2015 CU 28
- Microsoft Dynamics NAV 2013 R2 CU 40
- Microsoft Dynamics NAV 2013 CU 47
Also, important to notice, if you by any change installed the pulled NAV2016 CU15 or NAV2017 CU2 before they got pulled, please upgrade to either CU15.1/CU2.1 or better yet, this months release.