Question & Answer
Question
I am using the foreach transformation in an XML map to copy data from one array type to another. How do I access and use the iteration counter?
Answer
The foreach iteration counter can be read using the position() XPath function. To use it in your XML map create a custom XPath transform.
For example, say you want to insert the string "This is element number 1" in the first array element processed by the foreach, "This is element number 2" in the second array element and so on.
In the map inside the foreach transform, click on any field on the left side and drag it to the target field (a string type in this case) on the right. A Move transform is created. Click the triangle beside Move and navigate to Custom Transforms>Custom XPath. This changes the Move into a Custom XPath. In the properties view select the General tab and type
concat('This is element number ',position())
When you run this map on the server the target field of each element in the output array will contain the string described above.
Was this topic helpful?
Document Information
Modified date:
15 June 2018
UID
swg21450489