Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
sushantV
Creator
Creator

Passing globalMap variables to all the subJobs in a Job

I am working with multiple jobs that share 60% of same code. Every time I've to update something, I end up changing same stuff in all the jobs.

 

Here is how it looks:

Existing Job 1 - Node ETV -> Node 1 -> Node 2 -> Node 3 -> Node ABC  -> Node 5 -> Node 6

Existing Job 2 - Node KJL  -> Node 1 -> Node 2 -> Node 3 -> Node MNP -> Node 5 -> Node 6

Existing Job 3 - Node LDG -> Node 1 -> Node 2 -> Node 3 -> Node XYZ -> Node 5 -> Node 6

 

I want to make them all work like:

Create Sub Job 1, which is combination of Node 1 -> Node 2 -> Node 3

and

create Sub Job 2, which is combination of Node 5 -> Node 6

 

And then rewrite the jobs as following:

Updated Job 1 - Node ETV -> Sub Job 1 -> Node ABC  -> Sub Job 2

Updated Job 2 - Node KJL  -> Sub Job 1 -> Node MNP -> Sub Job 2

Updated Job 3 - Node LDG -> Sub Job 1 -> Node XYZ -> Sub Job 2

 

The issue is, apparently the scope of globalMap is limited and in no way it is 'global'. The values created in Node ETV aren't accessible within Sub Job 1. Can't seem to get past this thing. There must be create variables which are accessible everywhere within the job.

 

Labels (2)
2 Replies
Anonymous
Not applicable

GlobalMap values are global within the job class (take a look at the code to see what I mean). They aren't unfortunately global in respect to jobs with child and parent jobs. A way around this is to create a routine with static variables and ensure that all jobs in the hierarchy are running in the same process.

 

A very basic example of the sort of routine you will need is below.....

package routines;

/*
 * user specification: the function's comment should contain keys as follows: 1. write about the function's comment.but
 * it must be before the "{talendTypes}" key.
 * 
 * 2. {talendTypes} 's value must be talend Type, it is required . its value should be one of: String, char | Character,
 * long | Long, int | Integer, boolean | Boolean, byte | Byte, Date, double | Double, float | Float, Object, short |
 * Short
 * 
 * 3. {Category} define a category for the Function. it is required. its value is user-defined .
 * 
 * 4. {param} 's format is: {param} <type>[(<default value or closed list values>)] <name>[ : <comment>]
 * 
 * <type> 's value should be one of: string, int, list, double, object, boolean, long, char, date. <name>'s value is the
 * Function's parameter name. the {param} is optional. so if you the Function without the parameters. the {param} don't
 * added. you can have many parameters for the Function.
 * 
 * 5. {example} gives a example for the Function. it is optional.
 */
public class ObjectHolder {

	public static Object value1;
	public static Object value2;
	
}

I've used Object as the class since you can make use of these with any class in Talend so long as you cast appropriately.

 

In my parent job I have this in a tJava component.....

routines.ObjectHolder.value1 = (Object)"Hello World";
routines.ObjectHolder.value2 = (Object)21;

In my child job (placed in the parent job), I have the following code....

System.out.println(((String)routines.ObjectHolder.value1)) ;
System.out.println(((Integer)routines.ObjectHolder.value2)+"");

You will have to keep in mind that using this may cause you some unexpected issues if you are running child jobs and changing values in parallel.

TRF
Champion II
Champion II

Global variables are visibles internally to one job and subjobs. If what call a subjob is an external job called by a tRunJob, you need to use context variables instead.