Complicated data transfer in Dynamics NAV
Hi team!
A few weeks ago I redesigned our service and it turns up more complicated than it was expected. The service uses some data in temporary tables as input and table count dramatically increased that time. The solution was to use another object as a buffer.
When we have to transfer (handle) lots of data we use tables instead of variables and arrays. Common examples are tables “Gen. Journal Line”, “Item Journal Line”, “Dimension Selection Buffer”, “Excel Buffer”, “XML Buffer”, other buffer tables.
What we do when we have to transfer lots of tables (more than 5)? We transfer all these tables:) Also sometimes we can see arrays in the standard. For example, codeunit 14931 “Factura-Invoice Report Helper” in Dynamics NAV RU:

In the picture, you see a possible scheme of complicated data

The scenario could be more complicated than just “give data and use data”:
- Calculate some new data on existing;
- Validate data;
- Check some rules/information;
- Populate that data into different modules/tables/systems;
- Check some alternative scenarios;
- Use data.
It could be at least 5 steps before we use data and all these steps could be handled in different objects, and they could need different part of these data…
Also, we could want to transfer different data outside tables: some managing flags or values.
In .NET we can just create a class or structure encapsulated all needed data but we don’t have this opportunity in Dynamics NAV. The solution in NAV world could be a codeunit with set and get methods.
The codeunit will store all the needed data and provide you with get and set methods. Once having that codeunit, you there will be no need to change signatures of your module methods.
Different scenarios could put data from different sources (API, document table 1, document table 2…). For example, in my previous article, I could use “data storage” (my brand-new name:)) codeunit instead of putting buffer tables (“Document Header Buffer”, “Document Line Buffer”) directly through the entry point.
The big advantage of this method is you don’t need to change signatures of your entry points.
Most common methods:
- AddRecord

Contact is a global temporary table.
2. SetRecords

3. GetRecords

4. Set and Get some value

Some standard examples:
- Codeunit 131004 “Library — Variable Storage” — queue-based storage, stores different variables;
- Codeunit 131009 “Library — Setup Storage” — stores setups.
Advice:
- Use global methods to get and set data;
- Use global temporary objects to store data;
- Use data storage codeunit without other objects in signature (populate all needed data beforehand).
