Accessing collections with the FOREACH statement
The FOREACH
statement, natural in C#, has been introduced in NAV 2016. It is commonly used in C# to iterate on instances of a structure with an enumerator, which is usually introduced by implementing the IEnumerable
interface. In NAV 2016, you can apply the same statement to enumerable .NET objects.
How to do it...
Now we will collect a list of table fields that have relations to other tables and show them in a factbox page. Data is retrieved from object metadata in the XML format, and FOREACH
comes in handy when iterating on lists of XML nodes:
The page in the following recipe consists of two parts: the main page and a
factbox
subpage. First we will create thefactbox
subpage. Create a page in the page designer, choose theListPart
page type, and select the virtual table2000000041
Field for the data source.In the page wizard, move two fields to the page, No. and FieldName, and complete the wizard.
In the page properties, set Editable to No and...