Looping Tip needed - map 2 diff doc lists together

Hello everyone, I would like to know if someone can provide help as to how to handle the following in webMethods, as this particular scenario I have not performed before and I seem to be stuck for some reason.

Let’s say that I have two document lists. One is named INVOICE_LIST_ITEMS and another one is named INVOICE_LIST_MOREITEMS.

They are linked together by a field within both lists named LineItemNumber. That’s the only field that both have in common.

Whereas INVOICE_LIST_ITEMS has the LineItemNumber field in sequential order (first item = “00010”, second item = “00020”, etc), the second document list (INVOICE_LIST_MOREITEMS) can sometimes be out of order (first item = “00020”, second item = “00030”, third item = “00010”, etc)

I need to somehow say "loop over INVOICE_LIST_ITEMS, see what value is in the lineitemnumber field and find that same lineitemnumber in INVOICE_LIST_MOREITEMS and only if you find that match, you map the values (invoice number, totals, customer name, etc) from both document lists to the canonical document (which I’m simply calling INVOICE).

How do I make this happen?

Thank you for any tips that you can provide.


The search function here at wMUsers is highly recommended.


Thanks for the reply and now I know that utilizing appendtodocumentlist is better to use than looping over two different document lists, but the main part of my question that I’m having trouble visualizing is the part about ensuring that the link between the two doclists exists before mapping. I have to ensure that doclist1’s lineitemnumber field matches doclist2’s lineitemnumber field before mapping the contents of both contents to a canonical.

For example, only if doclist1’s lineitemnumber field states “00010” and doclist2’s lineitemnumber field states “00010”, can I then take the values of doclist1 (invoice_date, invoice_customer) and doclist2 (invoice_item, invoice_itemtotal) and map it to the canonical and then on and on with seeing if there’s a match for the lineitemnumber “00020”, then mapping to the canonical and on and on. If there is not a match, nothing is sent to the canonical.

This is more complex (at least to me and my limited experience) than taking two document lists and appending all the contents one after another to one big documentlist. My apologies if my original question was not worded correctly.


It is rather a simple mapping. You should use “loop” over (input array) INVOICE_LIST_ITEMS and inside that loop invoke another loop, this time over INVOICE_LIST_MOREITEMS. Now inside the second loop make branch (evaluate labels = true) and under branch make a mapping step with label “INVOICE_LIST_ITEMS/LineItemNumber == INVOICE_LIST_MOREITEMS/LineItemNumber”. In this mapping map whatever values you need.

This is of course the simplest way to achieve your goal, but is far from best performing one.


1 Like

Thanks for the response. Yep, I originally did coding in the fashion in which you’re stating, but because it took a long period of time for the information to come back, I was convinced that there must be a more efficient way to do this.

However, I appreciate your response, as it tells me that at least I was on the right track.

One more performant way to search a document list for a desired value is to convert it into a node and then use an XQL query to search for the desired value. There’s a 4-year-old post on that here on wMUsers that might be helpful.