Working with String lists

Hi,

I have 2 string lists.String list A contains let’s say a,b,c and d.String list B contains b,d and x.i want to create a new String list C which should contain elements of A minus elements in String list B.i.e in the above example,new list should contain a and c only.

Can someone tell me how to do this?

ramesh.

Hi,

i got confused as i was mapping the wrong string list.anyway got the solution for this.

ramesh.

Convert each string list to a java.util.Collection object. The classes that implement Collection include Vector, HashSet, ArrayList, and others. Use the removeAll method to get the relative complement of the sets. Then convert the modified collection back to an array for the pipeline.

Ramesh.,

Can you share us with your solution.

just curious to know,i know there are different approaches,as Rob also mentioned above.

Thanks,

RMG,

OuterLoop:Loop over List A
Map:A to tempElement
InnerLoop:Loop over List B
Branch
SEQ-----A<>B
assign tempVar=0
SEQ-----A=B
assign tempVar=1
Exit InnerLoop
Branch on tempVar
0:Map(append the tempElement to new StringList)

ramesh.

RMG,

Indentation didn’t work in the previous post.

OuterLoop:Loop over List A
–Map:A to tempElement
–InnerLoop:Loop over List B
----Branch
------SEQ(if A<>B)
--------assign tempVar=0
------SEQ(if A=B)
--------assign tempVar=1
--------Exit InnerLoop
–Branch on tempVar
—0:Map(append the tempElement to new StringList)

ramesh.

Thanks,thought of the same solution.

Anyways thanks for sharing with us.

Cheers,

Hi all,
I have a string list. I have a string field which has a value and should be mapped to the string list. Its in a loop.
So each time it gets mapped, it should form a list of string in the string list with various values.

I mapped the String field to the String list. But its not giving me any output.Do i need to add any transformer in between the string field and the stringlist or just a simple map.

Please let me know. Thank you

See the built-in services guide description of pub.list:appendToStringList.

Mark

Hi Stepheny,
Do as follows:

LOOP (InArray: SomeList, OutArray: DesiredStringList)
---- Map StringField to DesiredStringList (Here you will see that DesiredStringList appears as String: which is usual)
ENDLOOP
STEP AFTER LOOP

When you complete the loop and come the step “STEP AFTER LOOP”, you will see the DesiredStringList as stringList with all the various values populated.

Regards,
Bhawesh

What should i write in the InArray ?
What do u mean by somelist ??

Plz let me know
Thankyou

Hi Stepheny,
As you wrote:
“I have a string list. I have a string field which has a value and should be mapped to the string list. Its in a loop”.

Based on this, I assumed you have another List and you are looping based on that List. If only List you have is this DesiredStringList, do as follows:

LOOP (InArray: DesiredStringList)
---- Map StringField to DesiredStringList (Here you will see that DesiredStringList appears as String: which is usual)
ENDLOOP
STEP AFTER LOOP

When you complete the loop and come the step “STEP AFTER LOOP”, you will see the DesiredStringList is back as stringList with all the elements in this list populated with the value of StringField.

Regards,
Bhawesh

I dont know, but something is going wrong. That doesn’t work.
May be my question is wrong. Let me reframe my question.

I have a document which contains a field- A which is a string.
I have a document reference which contains a Stringlist- B
(I dont know whether these documents could make any difference.)

There is a loop on the document of A and each the time the loop runs A gets a new value. So if the loop runs 4 times then i have 4 values for A.
I need to store this 4 values of A’s in B.
So before i come out of the loop i should have the B ready with 4 values.

Sorry if my question was wrong before.
Please tell me what should i do for this ? iam trying to use list.append:stringlist,but its giving me error.
In the tolist i have given B
In the fromitem i have A
and in the serviceout tolist i gave B.
Am i going wrong somewhere ??

Thankyou

Stepheny,

From your problem statement it looks like the source (where you have string field A) is a document list and not a document, so when you loop over that document list, in each iteration of loop, there is a new value for field A.

With the assumption above, what you are doing looks okay, except for one thing - the name of the service to append is pub.list:appendToStringList. May be you just made a typo. I tried this and it works -

Loop [inArray = document that contains A]
|—pub.list:appendToStringList [(inputs)A-> fromItem, docRef/B->toList (output)toList->docRef/B]

This should get you the result you are looking for… if you are doing just this and still getting an error, post the error message that you are getting.

HTH, Rohit

Place this service under Loop step pub.list:appendToStringList will do the trick.(Make sure you drop the fromItem,string)

Loop(Stringlist)
map string to appendToStringList (drop the fromItem)toList to originaltargetStringlist

Come out of loop step,originallist should have the new list

Rohit’s suggestion also works great…

HTH,
RMG

Iam sorry to ask u again about this.

In the pub.list:appendToStringList i did not understand what are the inputs that are given to the service.

In the “tolist” i could not give document reference as input … (it does not allow)
Do i need to give the stringlist B as an input to the "tolist " which is in the document reference. As the service appends strings to stringlist i cannot give document reference as input to that service.
When i tried giving the Stringlist B as an input to the service, it throws an exception.

Let me make the question clear again.

pipeline In

Document
field1
field2
string A

Doc Reference
Document
DocumentList
String1
String2
StringlistB

pipelineout

Doc Reference
Document
DocumentList
String1
String2
StringlistB

plz tell me the solution. Sorry for troubling u all.
Thankyou

The error its giving is “error occured while tracing”

Hey i got the solution…May be its temporary.
Its not allowing me to map when its in a document reference, but if i store the values in a stringlist which is not in any document or reference document, then its allowing me to append.
And after i appended all the strings to that stringlist, then i mapped that list to tha list in the document.

Thank you for all your help.
If there is some other solution, plz let me know.

hi all,
I have one more question on this.
Now i got a stringlist, but I should check before inserting into the stringlist that the string already exists or not . If the string already exists, then i should not insert. If it doesn’t exist, then i should insert.
Can someone give me ideas, how to do that ?
Are there any builtinservices to do that ?
Thankyou

Hi Stepheny,
To conditionally append the string to a stringList, use the branch statement.

Also, wrote about your pipeline In/Out again something like this:

Document
—field1
—field2
—string A

AND

Doc Reference
—Document
—DocumentList
------String1
------String2
------StringlistB

Then only we could suggest you the correct advice. The mapping logic will chage based on your document structure.

Regards,
Bhawesh