How Can I Count How Many Iterations Occurred on a Source? (Magic xpi 3.x)
When you work with Magic xpi’s Data Mapper, you might have situations where you need to know how many Source records you have. You might also want to define a different value in a certain field for every x number of records, or you might have a flat file Source where every x number of records are header lines and the remainder of the lines are related to those specific headers.
Magic xpi lets you count these Source records easily.
Note:
|
This topic assumes that you have already built and are working with a project containing a Data Mapper.
|
Counting the number of iterations that occurred on a Source:
After you have opened the project where you want to count the Source iterations, you should follow these steps:
-
Right-click on the relevant flow and select Variables.
-
In the Variables for Flow dialog box, select the Flow Variable tab.
-
Click New and create a new flow variable called F.counter. Set the variable’s type as Numeric.
-
Right-click on the Data Mapper whose Source iterations you want to count, and select Configuration.
-
In the Source/Destination Management dialog box, click Map.
-
In the Data Mapper window, right-click on the parent compound node in the Destination pane and select Properties.
-
In the Node Properties dialog box, select the Advanced tab. Here, click New to create a new line.
-
In the Variable Name column, click the button and select your F.counter variable.
-
In the Expression column, click the button and enter the following expression: F.counter +1
This means that for each iteration a value of 1 is added to the F.counter variable, which starts from 0.
Note:
|
This iteration count takes place before any condition that you may have defined on the Destination node is executed. If you defined a false condition on the Destination node, you will receive the number of mapping attempts instead. To avoid this happening, and to obtain a true iteration count, you should define the same condition in the Node Properties dialog box’s Condition column as well.
|
-
Click OK to close the Data Mapper window and the Source/Destination Management screen.
-
Set a breakpoint, and then debug the flow by right-clicking on the flow in the Navigation pane and selecting Debug.
-
Run your project by clicking the Run/Continue Project button on the toolbar.
-
Click the Context View button on the toolbar to open the Context View window.
-
In the Context View window’s Flow Variable tab, you will see a value in the F.counter variable row’s Value column. This value is the number of iterations that occurred on your Source.