Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
tale103108
Contributor III
Contributor III

Loop through input file to populate context variable to be used in job

Talend 5.4
Linux 6.2
I want to read a text file that contains one value per row, use that value to populate a context variable (or a variable) and then go to a sub job that uses the variable, then repeat through file (and the process) until the end of file.
How to do?
Thank you all.
Labels (2)
4 Replies
Anonymous
Not applicable

Hi,
From your description, it seems that you are looking for tContextLoad or Implicit tContextLoad.
Could you please take a look at component: TalendHelpCenter:tContextLoad
and a forum about How to use Implicit tContextLoad in use case  https://community.talend.com/t5/Design-and-Development/resolved-Iterate-through-a-list-of-URL-s-for-... to see if it is satisfying your needs?
Best regards
Sabrina
tale103108
Contributor III
Contributor III
Author

In the link you provided, if you look at some of the responses, Shong comes close to what I am looking for when he states the following:
You can use tFlowToIterate to iterate all rowss one by one, for example:
tFileInputDelimited--main(row1)-->tFlowToIterate--iterate--tRSSInput--main--tLogRow
on tRSSInput, set the RSS URL field as: row1.url

However, what I need in place of the tRSSInput would be a tContextLoad.  And then once the context is loaded I need to call another subjob to use that context.  Then I need to repeat this step for each row in the tFileInputDelimited.  That input file, by the way, would have the following structure (i.e. same context key, different values):
name=John
name=Carol
name=Joan
...
Please advise and if you have a snapshot of the flow that would help tremendously.
Jcs19
Creator II
Creator II

In the link you provided, if you look at some of the responses, Shong comes close to what I am looking for when he states the following:
You can use tFlowToIterate to iterate all rowss one by one, for example:
tFileInputDelimited--main(row1)-->tFlowToIterate--iterate--tRSSInput--main--tLogRow
on tRSSInput, set the RSS URL field as: row1.url

However, what I need in place of the tRSSInput would be a tContextLoad.  And then once the context is loaded I need to call another subjob to use that context.  Then I need to repeat this step for each row in the tFileInputDelimited.  That input file, by the way, would have the following structure (i.e. same context key, different values):
name=John
name=Carol
name=Joan
...
Please advise and if you have a snapshot of the flow that would help tremendously.

I would replace tRSSInput by tJavarow and tLogRow by tRunJob (your child job)
tale103108
Contributor III
Contributor III
Author

I figured this out by just using tJavaFlex in place of tRSSInput and adding some Java (see below)....

context.name = ((String)globalMap.get("row1.name"));
row2.name = context.name;


thanks for all your help.