One Star

[resolved] Passing Context Variable from Child Job to Parent Job

Hi,
I know that there are a few posts on this subject, but unfortunately none seem to work in my situation. I am running Talend 3.1.3. I have a parent job that sets first sets context variables using a TJava component. It passes the variables to the child job (works fine) via the Transmit Context option. The the child job then does some data manipulation and also sets some additional context variables and needs to pass them back to the parent job.
I have a tFixedFlowInput component that feeds a BufferOutput component in the child job. (This was one of the solutions posted in another thread) In the parent job, I have a tBufferInput that is linked to the output of the tJob component. I've tried linking a tJavaRow component to the tBufferInput to assign the context variables and I've also linked a tLogRow to the tBufferInput. As far as I can tell, the tBufferInput doesn't work for a parent/child job scenario as no data is being passed.
Can someone help me to understand how to pass a context variable value from a child job to a parent job?
Thanks,
Steve
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] Passing Context Variable from Child Job to Parent Job

Issue, finally resolved. I can see why there is a disconnect on this forum. Most ETL developers that come from the DW world are not Java programmers and most Java programmers are unfamiliar with DW concepts. As Talend draws more ETL developers from the DW space, this will hopefully become less of an issue.
The tBufferOutput does work to pass a value to a parent job if you link a tJava row to the tRunJob output and assign the context variable with context."<variable name>" = input_row.<input_row_name>. However, you will not see this variable assigned if you link a tJava component to it with a System.out.println(context.<variable name>) linked to it with either a row --> main link or a onComponentOk link. This must have something to do with the scope of the variables in the code being generated. You will only see it assigned if you link your input component to the tJava component via onSubjobOk.
Thanks to Parham for helping me to see the light,
Steve
5 REPLIES
Community Manager

Re: [resolved] Passing Context Variable from Child Job to Parent Job

Hello Steve
I have a tFixedFlowInput component that feeds a BufferOutput component in the child job.

You are going the correct approach,
on child job: using a ttFixedFlowInput to fix one row and set the value as value of context var, and link it to a tBuffterOutput.
on father job: link the tRunJob to a tJavaRow, define the schema of tRunJob as tBuffterOutput's schema, on tJava, assign the value to global var or context var. eg:
globalMap.put("mykey",input_row.reslut)
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: [resolved] Passing Context Variable from Child Job to Parent Job

Thanks Shong. I have a couple of clarifying questions regarding your statement "link the tRunJob to a tJavaRow, define the schema of tRunJob as tBuffterOutput's schema, on tJava, assign the value to global var or context var. eg:
globalMap.put("mykey",input_row.reslut)"
1. Where you say tJava, I'm assuming you mean tJavaRow?
2. To assign the value to a context var, should the statement be context.JobId = globalMap.put("mykey",input_row.result);?
3. For the "mykey", should that be the name of the output port?
Thanks,
Steve
One Star

Re: [resolved] Passing Context Variable from Child Job to Parent Job

Does anyone have a step by step (with screenshots) as to how to set up a global variables on a parent job, then change the var value at the Child then use that value again in the parent (ie. - tSendEmail)? I'm a little confused looking at the textual explanations. Thanks.
One Star

Re: [resolved] Passing Context Variable from Child Job to Parent Job

Issue, finally resolved. I can see why there is a disconnect on this forum. Most ETL developers that come from the DW world are not Java programmers and most Java programmers are unfamiliar with DW concepts. As Talend draws more ETL developers from the DW space, this will hopefully become less of an issue.
The tBufferOutput does work to pass a value to a parent job if you link a tJava row to the tRunJob output and assign the context variable with context."<variable name>" = input_row.<input_row_name>. However, you will not see this variable assigned if you link a tJava component to it with a System.out.println(context.<variable name>) linked to it with either a row --> main link or a onComponentOk link. This must have something to do with the scope of the variables in the code being generated. You will only see it assigned if you link your input component to the tJava component via onSubjobOk.
Thanks to Parham for helping me to see the light,
Steve
One Star

Re: [resolved] Passing Context Variable from Child Job to Parent Job

I am running Talend 4.1.2 and i have the same problem. There are some news? I need to link tJavaFlex to tRunJob through a main connection but in this way i'm not able to read child context because isn't setted so i reiceve the message: tContextLoad_1 set key "null" with value "null"
if you use a "onSubjobOk" connection everything works fine, if you use a "main" connection it doesn't work becouse you can't find the code below:
for (String[] item_tRunJob_1 : childReturn_tRunJob_1){

if (0 < item_tRunJob_1.length) {
row1.key = item_tRunJob_1;
} else {
row1.key = null;
}
if (1 < item_tRunJob_1.length) {
row1.value = item_tRunJob_1;
} else {
row1.value = null;
}