Copy list on itself create dependencies

Hello,

I’m stuck with a weird demeanor on webMethods 7.1

Let me explain:
I’ve got a document reference including a document Reference List.
In this list I’ve got 2 fields (string) one we call case1 and th other case2.

First step, I have to replicate the list:
if my list is A;B;C , I want A;B;C;A;B;C (there is plenty of manners to do this)
next I have to map values from another list like this:
A.case1= value;B;C;A.case2=value;B;C

to do this I have a lenth of list (3 in the example) I create 2 int one equal to $iteration-1 and the second equal to the first one plus the length of the list and then I map my value to case1 and case2 with 2 differents indexes.

If I run only the part that map values to a list type A;B;C;A;B;C I get what I want
BUT if I run the part that copy the list what I get with the map of th value is:

A.case1=value A.case2=value;B;C;A.case1=value A.case2=value;B;C

what does explain this dependencie between the two A (the original and the copy) ?

Thank you very much for your help.

Can you post the steps you are performing in the loop? It’s likely that you’re getting caught by the “copy by reference” vs. “copy by value” behavior. If you’re mapping at the document level, it is copy by reference. If you’re mapping at a field level, it is copy by value.

Typically in looping one uses a work record. It is important to drop that record from the pipeline for each loop iteration otherwise you’ll keep modifying the same record for each iteration.

I tried several means to copy the list: pub.list:appendToDocumentList with the list in toList and fromList , copy one by one in a loop, map from the list to a work list…
I’m at loss why every method create a dependencie between the source and the copy.

even when I create two separate lists from the source, if I map only to one of theese the second is also updated. It’s quite driving me mad.

Thank you for your help.

Please post the details of your loop and the mapping steps. I’m certain someone here will be able to point out the correct way to do what you need.

When thinking about lists, it can be useful to keep in mind that they are simply Java arrays under the covers. In a Java array, if you want unique objects in each array element, you need to create a new object. If you copy an object from one array position to another, those 2 positions refer to the same object.

Same sort of principle applies to documents, which are really just Java objects (similar to a hashmap). If you want a new document, you need to create one, not map one document to another.

I tried theese steps:

loop over /entrylist
-map $iteration-1 → counter
-map entrylist[i] → temporary element of List
-map temporary element of List → exitList1[%counter%] with drop of temporary element List

I do it twice(with a second loop) and I’ve got 2 lists exitList1 and exitList2 but they are still linked. What is the correct pattern ? Or what do I do wrong ?

Thank you for your help.

I found a way to obtain what I want:
map every field of my element of list instead of simply map the element.
It’s a bit of a hassle but it works.

thanks for your help

That is indeed the way to go (copying each element, not the record). Copying the record did a copy by reference: You had multiple pointers to the same record in multiple places. That’s why that were “linked”.

loop over /entrylist
-map $iteration-1 → counter
-map entrylist[i] → temporary element of List <— Map the fields, not the docs
-map temporary element of List → exitList1[%counter%] with drop of temporary element List <— Okay to map the docs here (always drop the temp)