best practice loop

hi Experts,

Thanks for reading this thread.
Question is the following:
What is the best way to copy values from an input list to an output list?

  • loop over the input list and appendToDocList? (not what I would go for)
  • specify in-array and out-array on the loop? (probably my preferred solution)
  • no loop, just mapping of elements from the input list to the output list (is it safe to develop this way)
    Apparently, the third way does work (so far at least), it just looks so terribly wrong, and I can vaguely remember doing it and running into issues some time ago…

Anybody care to comment on this?

cheers,

Loic

Using in-array and out-array on a loop is generally the way to go.

appendToList tends to bog down when the number of elements gets to be several hundred (there are threads on this).

If plain ol’ mapping does what you need, keeping elements in the right places and in the right order, then would seem to be little reason not to do it this way. Can you share the example you’re using?

If you use In-Array and Out-Array when there are conditions to be applied on mapping inside the loop, then you probably would get some empty or null docs in the final list. If all you need to do is one-to-one field mapping, then you can directly map the fields from List1 to List2, as Rob Said.
Adn finally, this depends on your requirement.

Cheers
Guna

Hi Guna, Rob,

Thanks for commenting on this. Pretty much the reaction I would have expected.
For the sake of the example : it is indeed one-one mapping, just copying values from one list to the other.
Apparently, the IS gets mixed up when you use transformers though, so like you both say - as long as its simple…
Thanks for the input!

Cheers,

Loic

“IS gets mixed up when you use transformers though”

This is a popular opinion but not accurate. Even if you call a service directly, instead of via a transformer, it won’t know how to deal with a list if that’s not what it accepts as input.