Take comma separated string and input into list

Four Stars

Take comma separated string and input into list

Hi,
I have a string input as a context (myContext = "item1,item2,item3,item4") and I want to be able to iterate over the comma separated values. I have used a tNormalise component to separate out the elements of the string but can I load these into an array so that I can create an iterative loop and do something with each element?
Thanks,
Dan
Sixteen Stars

Re: Take comma separated string and input into list

Yes you can. If you are receiving them in a context variable, you can use a tJavaFlex. Convert them to an ArrayList in the Start Code section and then open a While loop in that section. Use the Main Code section to do whatever you want to do with the ArrayList (maybe output a row for each value?) and then close the loop in the End Code section.
Although I am not doing precisely this in this tutorial (https://www.rilhia.com/quicktips/quick-tip-row-multiplication) it demonstrates how you can generate rows using a tJavaFlex. If you have some Java, you should be able to extrapolate.
Thirteen Stars

Re: Take comma separated string and input into list

You can do as described above with tJavaFlex,
as alternative You can use 
tInputXXX -> tNormalise -> tFlowToIterate  and then continue work with single element in Loop
tInputXXX -> onSubJobOk - will continue Job after finish the loop
-----------
Four Stars

Re: Take comma separated string and input into list

Thanks both, vapoukov's method works a treat and avoids me using any java. Rilhia Solutions looks like a great resource - thanks.
Four Stars

Re: Take comma separated string and input into list

I have also come across this scenario, I have fixed my issue by using below flow

trowgenerator> tnormalize > tflowtoiterate > tjava

[Note: In tRowGenerator you have to get the context variables ,which you have in your configuration file.Then In tnormalize component  separated by comma ]