Using Generic List in .NET

If you need to temporary store an array of values for later processing, you normally use and Array or a temporary table.
Array in Dynamics NAV is not dynamic and you cant search.
Temp table can be risky or has trigger code. But you can create a new table outside your license range, but again another object for a small task.

In comes .NET Generic List.
A simpel class for storing, retrieving and looping values.

Below is an examble that stores Item Numbers to a list, loops it, and finally queries the List if a specific Item Number exist in the List.


// Create instance of List
ItemList := ItemList.List();

// Loop and add data to List
Item.SETRANGE("Gross Weight", 10);
 // Find out if you want to store the Item No. 
 ItemList.Add(Item."No."); // Add Item No to the list
 UNTIL Item.NEXT = 0;

// Loop the list (NAV2016)
FOREACH TextVariable IN ItemList DO BEGIN

// Loop the list (Pre NAV2016)
FOR i := 0 TO ItemList.Count() - 1 DO BEGIN

// Check if Item No exist
IF ItemList.Contains('000001') THEN BEGIN
 MESSAGE('Item exist in list');

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s