Category Archives: Tips & Tricks

Getting out of the DateTime mess, or how to get Utc DateTime in C/AL

Today at work I was trying to untangle one big bowl of spaghetti called DateTime. It’s the C/AL DateTime I am talking about, not System.DateTime from .NET.

The problem with C/AL DateTime is that no matter what you do it’s, according to documentation, “always displayed as local time”.

Another problem with C/AL DateTime is that C/AL is a bit rude when it comes to System.DateTime: whenever C/AL compiler (or runtime) encounters a value of System.DateTime it’s automatically converted to C/AL DateTime.

When you combine those two problems, you get the following problem: even though System.DateTime is perfectly capable of handling time in both UTC or local kind, C/AL isn’t.

To prove this point, just run this:

MESSAGE(‘Current local time: %1\Current UTC time: %2’,SystemDateTime.Now,SystemDateTime.UtcNow);

It will show this:


And I am currently sitting in a UTC+1 time zone, mind you.

Continue reading Getting out of the DateTime mess, or how to get Utc DateTime in C/AL

Deploying from Visual Studio, update

A few days ago I have published my PowerShell script that streamlines and automates deployment of control add-ins from Visual Studio. Over the past couple of days I have improved it a little bit, and fixed a few bugs, so here’s an updated version that is more resilient to your project structure, produces resource zips that NST not only extracts, but actually understands, and does a little more.

Continue reading Deploying from Visual Studio, update

Out-of-transaction database writes

Ancient wisdom goes that you cannot have more than one write transaction going on at the same time in a single session in NAV.

This is absolutely true, in and out.

Some features, like Activity Log, will leave you wanting to be able to write to the database outside of the normally running transaction.

Wouldn’t it just be beautiful if you could:

  • Write to the database, and then persist the change to the database even if an error happens during the transaction? (without cough! TryFunction, cough! cough!);
  • Not cause any locks to remain at the target table for any longer than it takes to do the write itself, without having to call COMMIT on your “regular” transaction; and
  • Not use temporary tables, because a system error (however unlikely) could cause the data to not be persisted if crash happens before temporary table is flushed to the physical one.

Well, in fact, you can do this.

Continue reading Out-of-transaction database writes

Sorting out the DLL hell, Part 3: The Code

[Update, February 8, 2016: there is a new version of code from this post. Please check]

Okay here we go. In this post I deliver the promised code that handles automatic deployment of all your assemblies to client and server, as needed.

For any of you who haven’t read the last two posts, I am talking about automatically deploying .NET assemblies to clients and server, from the database, on demand, at runtime.

This will be heavy on code, so fasten your seatbelt and brace for impact.

Continue reading Sorting out the DLL hell, Part 3: The Code

Sorting out the DLL hell, Part 2: The Solution

Deploying .NET assemblies to clients and servers in need is no simple affair. In my last post I have explained the problem, and announced the solution.

As promised, in this post I bring you the solution.

To be fully honest, this post only brings the conceptual solution, just a little brain game for you to train your .NET brain muscles a bit. The actual code I’ll deliver in the next post.

Continue reading Sorting out the DLL hell, Part 2: The Solution