NAV – Some basic functions #1

When working with Data in Microsoft Dynamics NAV, there are some functions you do not need often, but if you need them, you will probably need to run them on many tables at once.

One example is truncating all the data in some tables. Yes, there is a function for that: DELETEALL.

But it is a lot of work to define a bunch of variables for the tables, name them in a speaking maner and use DELETEALL on the variable

Here is what you could do instead:

Use a new or existing Codeunit “Basic Functions” and include this function:

TruncateTable(TableID : Integer)
recRef : RecordRef

recRef.OPEN(TableID);
RecRef.DELETEALL;

Now you just need to run this function.

It could look like this:

Basics.TruncateTable(50000);

Basics.TruncateTable(50001);

Basics.TruncateTable(50002);

Basics.TruncateTable(50003);

Basics.TruncateTable(50004);