Working With Results
In programming, row-by-row processing of result sets often plays a central role as it enables efficient handling of data. This approach allows access to each element in the result set and the application of specific operations on individual rows or records.
In XenoGuard, there are two actions for row-by-row processing of data sets:
- For Each: This action allows you to iterate through all records of a result list. The actions for processing the records are placed inside the loop.
- Get Row: This action enables you to read a single record at a specific position from the result set. To use it effectively, it should be embedded in an outer loop, such as a For Loop.
For Each
The For Each action iterates through all elements of a result list and enables the execution of specific actions for each currently processed element without the use of indices. This increases script clarity.
In the following example, the script reads the contents of an Excel spreadsheet Persons and iterates through the data row by row, storing each record in a database within the inner branch.
Get Row
Unlike For Each, the Get Row action processes a single record, specified by the Row Index input parameter.
Here's an example:
In line 5, Directory Get Files is used to read all Wave files from the Windows media folder. Then, a For loop is employed to select five files from this collection. This is done by first generating a random file index (line 8) and then passing it to the Get Row action, which reads and processes the data at that specific position. After forming the complete file path, the file name is displayed in a message box and the media file is played using Play File.
Referencable Result Structures
In XenoGuard, the actions For Each and Get Row are used for processing data structures. They require a reference to a result list or a corresponding data structure as input parameters. However, not all data structures are suitable for referencing.
The validity of a reference in XenoGuard depends on the internal structure of the data. The software identifies consistent, recurring data patterns as referencable result structures. These patterns can appear in various formats, such as Excel, JSON, or text files, and enable efficient and precise data manipulation. |
Examples of referencable result structures include:
-
Excel Tables: Tables are processable if they have a constant number of columns. Ideally, they should have column headings.
-
File and Folder Lists: These list files or folders in a repeatable format.
-
Tables from Text Files: Here, row-by-row representations, where data appears at regular intervals and in a consistent format, are processable.
-
JSON Structures: Recurring structures within JSON data, such as a list of objects with identical keys, are also referencable.
While setting a reference using drag-and-drop, the drop cursor in XenoGuard indicates whether a result structure can be referenced. The following figure illustrates this:
The first example shows an attempt to reference the Result List parameter. Due to non-recurring internal elements (File Count), this reference is invalid. This is indicated by XenoGuard in the drop cursor as No drop operation allowed at this position. In contrast, in the second example, the reference is valid. The Files node shows a repeatable table structure that can be iterated in individual records. The drop cursor provides positive feedback with Place a reference to the parameter list on this cell. This way, you can recognize during drag-and-drop whether a reference is valid and accepted.
Named and Anonymous Result Structures
A unique feature when working with XenoGuard is the concept of anonymous result structures. These differ from traditional referencable structures in that their exact nature is not determined during the design phase of an action. It is only during runtime, i.e., when the action is actually executed, that the structure becomes apparent. A typical example is the content of a text file, whose exact structure and contents only become obvious upon reading.
One might think that such indeterminacy presents an obstacle in data processing. However, XenoGuard has an effective solution for this. The software offers a mechanism to convert these unknown, anonymous structures into named, known structures.
How does it work?
- One-time Execution: The first step is the one-time execution of the action that provides the unknown structure.
- Visualization by XenoGuard: After this execution, XenoGuard analyzes the resulting structure and presents it to the user as a result.
- Storage as a Data Template: This now-recognized structure can be directly saved as a data template as soon as the structure is referenced.
- Availability During Design-Time: From this moment, the previously anonymous structure is available as a named structure. This means it can be referenced during the design phase and used for further actions and processing steps.
Through this clever approach, XenoGuard minimizes the risk of errors due to unknown data structures and significantly simplifies working with dynamic data sources.