Map from one recursive doc to another


I am trying to map from one recursive document to another.

Basically my flow service has two steps, a map and a loop. I am looping over the recursive list and invoking the same service.

The document is used for a hierachical org structure and has a few fields (unitID,UnitDescription etc.) then it references a list of itself for all the child units, the data contains one parent record with two children, each of which have their own children and children of children etc.

Is this achievable using an output array in the Loop? Or should I be using appendToDocumentList? Or both?

I’ve tried many different combinations and I’ve only managed either a flattened structure, or overwritten hierachy structure.

Any tips?

Hi Slethborg,
How does your output looks like? Is your both Input and Output do have recursive structure?

Is the recursive document again a Document list or Single document in Input and Output?

I doubt if you can map to a recursive structure through appendTodocument list or output array in loop. Logically, those two are meant for creating a list, not document inside another document…

Try out the below steps…

Input doc structure for example…

–SampleDoc (reference)
----SampleDoc (reference)

Service: invokeRecursiveService

if (SampleDoc!=$null)
Map unitId, unitDescription to Output structure
Call invokeRecursiveService
default Exit

Try this and let me know…


Hi Senthil,

Yes both the input and output are recursive documents.

I managed to get it working, but with lots of positional variables (hierachy level counter, and array position counters) and using the indices property on each map.

I haven’t tried your proposed solution, but wouldn’t it just overwrite the output document on each recursive invoke? And if theres no loop to exhaust, wouldn’t it keep calling itself infinitely?

Hi slethborg,
Yes, condition is required to exhaust the loop…

Branch on %inputDoc/inputDoc% != null,
—invoke recursiveService…

I am able to invoke the service in recursive manner with inputs traversing one by one, but output as you said, is being over written with last value.

If I think of Fibonacci calculation also, the output will be a single variable that holds the result, not a recursive stuff.

Sure there should be some tricky in implementation in an efficient way to get this done, but more testing is required as it should not go in infinite loop at any cost. There is a possibility that it might fill up the call stack if goes in infinite…


If documents are quite complex and quite different, an xslt steps may bring better results. Transform your document to xml, use an xslt step, and transform resulting document back to document (or leave it xml if appropriate).

Pro: xslt is much more flexible in changing the structure of documents
Con: Document must fit into memory, you can’t use node iterator.



Thanks! I did exactly this and can now convert the 2.5 MB file in about 4 seconds! It was taking around 4 minutes using the loop method. Huge performance improvement.

Hi All,

I have a requirement with IS receiving xml and one of items in xml is recursive.Wondering if there is a way to find upto what level/depth the items in recursive list contains data?


Item->document list
Item->document list
Item->document list