How Can I Count How Many Iterations Occurred on a Source? (Magic xpi 4.5)
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:
-
Under the relevant flow, double-click Flow Variables to open the Flow Variables repository.
-
Click Add and create a new flow variable called F.counter. Set the variable’s type as Numeric.
-
Double-click (or right-click and select Configuration) on the Data Mapper whose Source iterations you want to count to open the Data Mapper window.
-
In the Data Mapper window, right-click on the parent compound node in the Destination pane and select Show Properties.
-
In the Properties pane's Multi Updates parameter, click to open the Multi Updates dialog box. Here, click Add to create a new line.
-
In the Variable Name column, click and select your F.counter variable.
-
In the Expression column, click 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's Properties pane’s Condition column as well.
|
-
Click Save.
-
Set a breakpoint, and then debug the flow by right-clicking on the flow in the Solution Explorer 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.