Five Stars

How to pass global variable from child to Master job

Hello,

 

I have a Master job and from that, I am calling a child job using tRunJob component. In my child job, I have a global variable named "ErrorMsg" which has details of any exception if generated in child job. I want to access this "ErrorMsg" global variable with its value even if it's empty or with some error message in Master job. 

 

Can anyone please help me to achieve this in Talend 6.3.1 data fabric 

 

Thanks & Regards

Vikas

  • Data Integration
1 ACCEPTED SOLUTION

Accepted Solutions
Seven Stars

Re: How to pass global variable from child to Master job

My reply is based on a solution suggested in this topic,

https://www.talendforge.org/forum/viewtopic.php?id=7604

I tried it and it works fine for my use case.

 

So to start with, in your child job, use a fixed flow component to create a single row with the value of the global Variable and then connect this to a tBufferOutput component.

 

AssignValueToBuffer.PNG

Once you send this data to tBufferOutput, you can use access this information by using the output link of the tRunJob component in your parent job. Just connect the output link of the tRunJob component to a tJavaRow component and set the values. For example, in the screenshot below, you can do something like -> "context.parentVariable=row1.globalVarValue;" in the tJavaRow component.

Also make sure that the schema of the tBufferOutput in your child job and the tRunJob component in your parent job are the same.

AccessValueFromBuffer.PNG

 

Hope it makes sense. I don't think this is an elegant solution but I haven't really figured out a better way to solve this particular problem.

Let me know if you do. Cheers!

 

3 REPLIES
Seven Stars

Re: How to pass global variable from child to Master job

My reply is based on a solution suggested in this topic,

https://www.talendforge.org/forum/viewtopic.php?id=7604

I tried it and it works fine for my use case.

 

So to start with, in your child job, use a fixed flow component to create a single row with the value of the global Variable and then connect this to a tBufferOutput component.

 

AssignValueToBuffer.PNG

Once you send this data to tBufferOutput, you can use access this information by using the output link of the tRunJob component in your parent job. Just connect the output link of the tRunJob component to a tJavaRow component and set the values. For example, in the screenshot below, you can do something like -> "context.parentVariable=row1.globalVarValue;" in the tJavaRow component.

Also make sure that the schema of the tBufferOutput in your child job and the tRunJob component in your parent job are the same.

AccessValueFromBuffer.PNG

 

Hope it makes sense. I don't think this is an elegant solution but I haven't really figured out a better way to solve this particular problem.

Let me know if you do. Cheers!

 

Five Stars

Re: How to pass global variable from child to Master job

Thanks for the detail explanation. It helped me to solve my issue, I had already read about tBuffer component but the problem was in my Master job from tRunJob I was not taking the Main connection to tJavaRow instead I was connecting it to tBufferInput with onComponentOk connection and then from there the Main connection to tJava.

Seven Stars

Re: How to pass global variable from child to Master job

You are welcome. Glad to hear it works.