Returns a new empty list of the defined variable type, and is used with other List-variable type Actions. CreateList initializes a typed, ordered collection within a Ruleset that can grow dynamically as data is processed — making it the starting point for any workflow that needs to accumulate, iterate over, or pass a variable-length set of values between rules.
Before You Begin: Creating a List Variable
CreateList operates on a List-type variable that must be defined in the Ruleset before the action can be used. To create a List variable, go to the Ruleset editor's Variables section, click Add Variable, type the name you wish to give the variable, select List from the Type drop-down, and select the Element Type. Choices are Boolean, String, and Number. Click OK — the new variable will then appear as an option in the Variables pane and can be assigned as the output of CreateList.
Properties
| Property | Type | Direction | Description |
|---|---|---|---|
| List | List | Output | The newly initialized empty list, typed according to the variable's defined Element Type (Boolean, String, or Number). |
CreateList takes no inputs — it simply resets or initializes the List variable to an empty state, ready to be populated by subsequent rules.
The List Action Family
CreateList is always used in conjunction with the other List-type actions. Together they form a complete workflow for building, reading, and iterating over dynamic collections:
| Action | Description |
|---|---|
| CreateList | Initializes a new empty list of the defined type. Always the first step. |
| ListAdd | Adds an element to the specified list. Used inside a loop to append values one at a time as records are processed. |
| ListGet | Returns an element from a list at a specified position. The position index starts at zero. Used when you need to read a specific item by its index. |
| ListSize | Returns the number of elements currently in the list. Used to control loop boundaries or check whether the list is empty before iterating. |
| ListRemove | Removes an element at a specified index position from the list. |
Typical Use Case
Collecting qualifying line items before writing output records
Suppose you are transforming an inbound 850 Purchase Order and need to pass only line items where quantity is greater than zero to the target document, while skipping lines with zero quantities. Rather than attempting to filter during the initial loop, you can collect qualifying lines into a List first, then iterate the List to write the output.
A practical example: the first rule uses the CreateList action with a List-type variable (e.g. ListField). A "For Each" Composite Rule then iterates over the source records — inside it, a ListAdd rule appends qualifying values to ListField. A second Composite Rule ("For each ListField…") then creates a new output record for each element in the list.
Step by step:
- CreateList — initialize
QualifyingLinesas an empty String list. - For Each source line item:
- Check if quantity > 0 (condition on the ListAdd rule).
- ListAdd — append the line item identifier to
QualifyingLinesif the condition is met.
- ListSize — retrieve the count of qualifying lines.
- For each QualifyingLines — iterate the list to write one output record per qualifying line item.
Another Common Pattern: Dynamic Lookup Values
CreateList is also useful when you need to build a lookup set at runtime — for example, collecting all unique product codes encountered in a document so they can be validated or cross-referenced downstream, without knowing in advance how many there will be.
Notes
- The Element Type set on the List variable (Boolean, String, or Number) is enforced — attempting to add a value of a different type will cause a type mismatch error. Ensure your source data is cast to the correct type before passing it to ListAdd.
- Lists in Cleo Rulesets are zero-indexed, meaning the first element is at position
0. - CreateList can also be used to reset a List mid-ruleset — calling it again on an existing List variable will clear it back to an empty state, which is useful when reusing the same variable across multiple loop iterations in complex rulesets.
- Lists are scoped to the current Ruleset execution and do not persist between transformation runs.
Related Actions
- ListAdd — append elements to the list during processing.
- ListGet — retrieve a specific element by index position.
- ListSize — get the current count of elements.
- ListRemove — remove an element at a specified index.
- List Variables — refer to the List Variables article for full setup instructions and a working example in the Ruleset editor.
Comments
0 comments
Please sign in to leave a comment.