The While clause is an extremely powerful feature that you probably won’t use frequently, but when you do it’s a god-send. Note that this is a part of the Do..Loop scripting convention. There is not a specific help page on the keyword.
Using While allows you to loop on a record within a load statement. It will basically keep loading that record until its condition is met. I like to think of them as mini-loops.
So take this super simple example. I have an array which is separated by pipes. I want to pull in the first three values of the array, but not any past that.
Data: Load * Inline [ Array 12|13|AAA|1 12|7|BBB|2|7Adkj ];
NewData: Load SubField(Array,'|', IterNo()) as ArrayValue, IterNo() as ArrayIteration Resident Data While IterNo() <= 3;
Drop Table Data;
IterNo() is a function that keeps track of the iteration you are on. You can leverage in your While clause as well as your field expressions.
This script example uses IterNo as the SubField parameter to pull out the first three values separated by the delimiter, produces my desired results.
One place you may have seen this used is in Master Calendar scripts floating around on the Community. I’ve seen it used to get a distinct list of dates quickly and/or to generate a new list of dates.
Let vDateField = 'Date';
AllDates: Load FieldValue('$(vDateFieldName)', IterNo()) AS EveryDate AutoGenerate (1) While Not IsNull(FieldValue('$(vDateField)', IterNo()));