One Star

Setting up context variable for tForEach Component

I have a tForEach component as a part of my talend project, which iterates a particular transformation for different states of a country. I want to set up the list of these states as a context variable so that each time I want to use a set of different combinations of the number of states. Is this possible?
Ex: I have 10 states in the tForEach component. For testing purpose, I want to use only 3 states to be processed. If it is not a context variable, everytime the list of states in the component needs to be updated on the job and re exported. I do not want to do that each time. Rather, I would like to set the list as a part of contexts and update the list according to requirement.
3 REPLIES
One Star

Re: Setting up context variable for tForEach Component

Hi
The code of tForEach is as seen below.
Object[] values_tForeach_1 = new Object[] { "newLine", };
for (Object tmp_tForeach_1 : values_tForeach_1)

I don't think you can use a context variable here which contains 10 or 3 states name.
Regards,
Pedro
Community Manager

Re: Setting up context variable for tForEach Component

Hi
Maybe you don't need tForEach component, you can set the value of context variable with more states delimited by a syntax, for example, "state1,state2,state3,state4", and then use a tNormalize component to normalize the column to more columns with item separator "," for example,
state1,state2,state3,state4
becomes
state1
state2
state3
state4
and then, iterate each row. The job design looks like:
tFixedFlowInput--main--tNormalize--main--tFlowToIterate--iterate--the rest of the job.
on tFixedFlowInput, add one column let's call it "states", set its value with context variable.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Setting up context variable for tForEach Component

Thanks Pedro and Shong.
@ Shong:
I will try doing as said. So, all I need to do here is not to disturb any other existing component, but set up a context variable for how many ever states I want to use and replace tForEach with a tNormalize component and set up the column name to be normalized with item separator ",". Is that right?
One quick clarification: Does this column name that we use in "Column to normalize" has to do with any particular field of a database table or how and where do we initialize/declare and map that column name to?
Thanks