{"id":23413,"date":"2015-09-08T00:59:55","date_gmt":"2015-09-07T19:29:55","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=23413"},"modified":"2015-09-17T14:45:06","modified_gmt":"2015-09-17T09:15:06","slug":"talend-passing-values-from-parent-job-to-child-job","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/talend-passing-values-from-parent-job-to-child-job\/","title":{"rendered":"Talend : Passing values from Parent Job to Child Job"},"content":{"rendered":"<p>In the previous <a href=\"http:\/\/www.tothenew.com\/blog\/content-migration-using-talend\/\">post<\/a>, I discussed automating content migration process using Talend. As the power of Talend lies with creating meaningful jobs, it solves a particular business problem. More often than not, one job has to talk to another job.<\/p>\n<p><strong>Use case:<\/strong><\/p>\n<p>While working on a migration project, I had a use case where I wanted to pass a value from a Parent Job to a Child Job.<\/p>\n<p><strong>Problem:<\/strong><\/p>\n<p><code>globalMap<\/code>\u00a0is a useful way to pass values, but it can only be used to pass the values within same Job. For Instance, If I have a <code>Job A<\/code> like\u00a0below:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-26349 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/09\/job11.png\" alt=\"job1\" width=\"399\" height=\"191\" \/><\/p>\n<p>where <code>tJava_1<\/code> is setting a key in <code>globalMap<\/code>,<\/p>\n<p>[java]globalMap.put(&quot;testVal&quot;,&quot;Test Value 1&quot;);[\/java]<\/p>\n<p>and <code>tJava_2<\/code>\u00a0is trying to retrieve its value.<\/p>\n<p>[java]System.out.println(&quot;testVal in the same job is &quot;+(String)globalMap.get(&quot;testVal&quot;));[\/java]<\/p>\n<p>Its value can be retrieved from the components defined in the same Job but if we try to access those values outside this Job, we&#8217;ll get the null value.<\/p>\n<p><strong>Solution:<\/strong><\/p>\n<p>The problem can be resolved by utilizing the power of <em><strong>&#8220;Context Variables&#8221;<\/strong><\/em>. Create a <code>Job 2<\/code>\u00a0like as shown below and define a context variable <code><em>\"testValue\"<\/em><\/code><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-26351\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/09\/job-3.png\" alt=\"job 3\" width=\"438\" height=\"247\" \/><\/p>\n<p>Create a <code>Job B<\/code> like as shown below: \u00a0(<code>Job 2<\/code>\u00a0is a <code>tRunJob\u00a0<\/code>component which is calling the above Job)<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-26352 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/09\/job2.png\" alt=\"job2\" width=\"394\" height=\"181\" \/><\/p>\n<p>Here <code>tJava_1<\/code> is setting a key in <code>globalMap<\/code>,<\/p>\n<p>[java]globalMap.put(&quot;testVal&quot;,&quot;Test Value 1&quot;);[\/java]<\/p>\n<p>To access the above value in <code>Job 2<\/code>\u00a0, define this component&#8217;s properties as below. Note the &#8220;<code><em>Context Param\"<\/em><\/code> definition, this is how we can set the value in the context variable and retrieve it in the child job.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-26354 aligncenter\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/09\/final-job.png\" alt=\"final job\" width=\"450\" height=\"312\" \/><\/p>\n<p><code>tJava_1<\/code> in Child Job can simply retrieve its value :<\/p>\n<p>[java]System.out.println(&quot;testVal in the another job is &quot;+context.testValue);[\/java]<\/p>\n<p>Hope it helps !!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous post, I discussed automating content migration process using Talend. As the power of Talend lies with creating meaningful jobs, it solves a particular business problem. More often than not, one job has to talk to another job. Use case: While working on a migration project, I had a use case where I [&hellip;]<\/p>\n","protected":false},"author":110,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":45},"categories":[1],"tags":[2007,2339,2337,2338,2340,2008],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/23413"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=23413"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/23413\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=23413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=23413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=23413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}