appendToStringList - need to divide the items into groups

I have document list containing list of 70 items. I need to loop through this document, create separate lists
of each 30 items. Inside the loop I have count variable which was initialized to 1 before the beginning of the loop.
Based on the count, I have sequence with appendToStringList service in it.
appendToStringList has input: toList, fromList and fromItem.
Mapped:
fromItem to document’s item number from input side
toList to List1.
Repeated the above for all the lists (List2, List3)
But after I completed the loop, I have:
List1: 0-49
List2: 0-70 ===> I only need items from 50-70

If I drop the tolist from second appendToStringList while adding items to List2, then List1 contains only one item,
that is 49th item.

===================
Here is the psuedo code:
count = 1
Loop:
Branch count
If count => 1 and count < 50
Add item number to List1
appendToStringList

If count => 50 and count < 100
Add item number to List2
appendToStringList
If count => 100 and count < 150
Add item number to List2
appendToStringList

By the end of the loop, I need:
List1:
item1 through item49

List2:
item50 through item99

I hope I am clear. Thank you for your help.

Please see the image attached for the above problem.
appendToStringListProblem.jpg

I’ve created a test service for appending to stringList, have two tips here:

  1. when append to list, make sure you map to the target List from left and also right. else the record will be overwrited
  2. make sure that the criteria is well specified, for example, if the first condition look like:
    %count% >=1 && %count% <=5; and the second condition should look like:
    %count% >=6 && %count% <=10

Hi,
I have seen the image you have attached and also the problem you stated. I suppose the problem is because you are not dropping the input document which is mapped to fromItem in appendToDocumentList service step. If I am not clear please take a look at the snapshots (Snapshots.zip)sequentially starting from Snapshot1, as attached and try. I hope it will work. Also take note of the following:-

  1. I guess you do not have to keep a separate varibale count instead you can use $iteration as it automatically gets increamented.

Best of luck!!

Kind Regards,
Soumik G Biswas :kiss:
Snapshots.zip (82.2 KB)

Question in the snapshot.zip.

In the snapshot3, Values doc list is dropped from rt hand side. So how did you get the Values doc list to snapshot 4. Do we need to recreate Values doc list for snapshot 4?

Hi,
I have dropped the Values document in both the child steps of the Branch so that it is formed again for the next values and the earlier values are replaced properly. If you do not drop it you will not find the desired outputs. If you see Snapshot2 then you will see I am each time forming the Values document in the first step of the LOOP, thus whether if I have dropped it in the 4th step I would form it again for the next execution and it will work fine.

As far as your question is concerned you do not need to recreate it and I have dropped in both the steps as both are child steps of a single branch step so as either of them will execute at a time and you will have no problems getting the document in the Snapshot4 step. Try this design and test it. I am sure it would work.

Kind Regards,
soumik G Biswas

In most cases, we should opt for Flow services over Java services (for more info on this topic, please run a quick search.) However, in my opinion, this is a good example of when a Java service would provide a cleaner solution.

Consider creating a simple Java service that takes 1 string list as input and outputs 3 string lists. In the Java service, you could use System.arraycopy (http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html) to easily accomplish what you need.

  • Percio