3

How can I iterate over a InputArray and load another input array with the same values except in lower case (I know that there is a string to lower function)?

Question: How to iterate over a String List with a LOOP structure?

InputArray: A, B, C

OutputArray should be: a, b, c

enter image description here

Doug Hauf
  • 3,025
  • 8
  • 46
  • 70

3 Answers3

5

In case, you want to retain the inputArray as such and save the lowercase values in an outputArray, then follow steps in below image which is self explanatory:

In the loop Step, Input Array should be /inputArray and Output Array should be /outputArray.

Steps and Output

ngrashia
  • 9,869
  • 5
  • 43
  • 58
  • You are defining the output array _before_ the `LOOP`. This is not recommended as the behavior is not defined. Anything can happen to the previous values and the values gathered inside the loop could be lost. If you want to add values from the loop iteration to a pre-existing list, it is better to use `pub.list:appendToDocumentList` or `pub.list:appendToStringList`. – gvlx Jul 13 '16 at 14:46
2

Your InputArray field looks like a string field. It's not a string list.

You need to use pub.string:tokenize from the WmPublic package to split your strings into a string list and then loop through the string list.

A string field looks like this in the pipeline:

enter image description here

A string list looks like this in the pipeline:

enter image description here

See the subtle difference in the little icon at the left ?

TchiYuan
  • 4,258
  • 5
  • 28
  • 35
  • 1
    When a stringlist is passed inside a loop as InputArray, it will appear in pipeline like string only. – ngrashia Jun 11 '14 at 10:03
  • 1
    The same for the output array: inside the loop you use it as a singular entity (can be a string, a document, etc.), outside, after the loop, it will appear as an array of the objects you used inside. – gvlx Jul 13 '16 at 14:42
2

I can see two cases out here.

If your input is a string

  1. Convert the string to stringlist by pub.string:tokenize service.
  2. Loop over the string list by providing the name of string list in input array property of loop.
  3. within loop use pub.string:toLower service as transformer and map the output to an output string.
  4. put the output string name in the output array property of Loop.
  5. once you come out of the loop you will see two string lists, one with upper case and one with lower case.

If your input is a string list.

In this case follow steps 2 to 5 as mentioned above.

dwitvliet
  • 7,242
  • 7
  • 36
  • 62
Adhiraj
  • 81
  • 1
  • 6
  • Take caution as `pub.string:tokenize` throws an exception if it does not receives a string (or is set to `$null`). To avoid encapsulating that call in a try/catch sequence I usually add a non-overwriting `MAP` of an empty string. – gvlx Jul 13 '16 at 14:38
  • Also, switch step 4 and 3: as stated in the Service Development Help, you MUST first set the output array name in the `LOOP` before using it inside. – gvlx Jul 13 '16 at 14:40