filtered mapping in a loop

Hello,

my problem is that I have to map one list into another list but I don’t want to map all list elements. List elements which don’t match to a special expression should not be mapped.

My solution now is

LOOP input array: array1  output array: array2
BRANCH 
   map if array1.name = abc into array2
   map if array1.name = cdf into array2
   map if array1.name = efg into array2

The problem is that also elements which shouldn’t be mapped have a empty node in the output array.

Is there another way but first to make a new list containing only the elements I’m interested in and then loop over this new list to map the elements?

Thanks Sabrina

Hi Sabrina,

Consider the built-in-services pub.list.appendTo... instead of using the output array. This way you can easily build a new list of values that can be of a different length than the source array.

Regards,
Adrian

Hello,
Yes services appendToStringList and appendToDocumentList are the common way for constructing a reduced size destination list from a particular source. It is a predifined entry on map steps under the Transformer tab button. Good day.

Yemi Bedu

Note that appendToStringList and appendToDocumentList performance does not scale well, because it requires allocating and filling a new array object on each call. If they are being called 100s of times or more, it would be better to use services that work on a true List object.

See WmSamples sample.complexMapping.largeDoc.messageBuilder createList, addToList and listToArray.

The usage would be

createList
Loop
   map
   addToList
listToArray

Thanks a lot, as there is no better way to solve
the problem I will do it this way.

Sabrina