How to access timestamp from C/AL? When you Google/Bing this question, you mainly get three answers:
- Short answer: you can’t,
- Write a SQL query using
- Create a SQL view and use a linked table on NAV
When Microsoft introduced NAV 2016, we got a fourth answer described in this blog post by Dynamics NAV Team Blog.
Here is my point of view about these solutions:
- Solutions 1: is not a solution,
- Solution 2: is like you use a hammer to kill a mosquito,
- Solution 3: well, this is not a solution too because:
- You have to create a view on your database and this will give some headache when you upgrade…
- You have to consume a table: what if you want to have the timestamp for records from two/three/N tables ? Would you create N dummy views and N linked tables? If it was me, the answer is a big NO.
- Solution 4: these is a great and useful improvement but:
- You may have to customize standard tables (add new field of type BigInteger and set property "SQL Timestamp" to Yes)… Yet another customized table you may need to handle during your upgrades 🙁
- What about older versions?
After this short introduction (short?), I get right to the point. Here is a fifth solution in three lines of code:
IF NOT DataTypeManagement.GetRecordRef(_RelatedRecord, RecRef) THEN EXIT(0); EVALUATE(timestamp, FORMAT(RecRef.FIELD(0).VALUE));
Want to try it? Here is the fob for Dynamics NAV 2013. In this fob, the function GetTimestamp returns the decimal value for the record’s timestamp.
This solution works for Dynamics NAV 2013 and later. Unfortunately, it does not work for Dynamics NAV 2009 R2 or older.