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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to access a Java variable?

Hi,
I've got a tJava and set a variable String var1 = "test";
Now I want to access this variable somewhere else, for example in a MsgBox or what else.
How can I access it?
globalMap.get("tJava_1_...");
There is only ERROR_MESSAGE .. _1_currentPath doesn't work either.
Can someone help me?
Thank you.
Labels (3)
9 Replies
Anonymous
Not applicable
Author

You need to use the globalMap map variable or create a context variable and use that. The scope of the tJava components is limited. You need a global scoped variable.
Anonymous
Not applicable
Author

Hello
Frist, you need to set it to a global var. eg:
String var1="test";
globalMap.put("varName",var1);
then, use this var like this:
(String)globalMap.get("varName")
Best regards

shong
Anonymous
Not applicable
Author

Hi,
it works within one job, but when I call tRunJob and try to System.out.println the variable in the childjob I see: null
For the tRunJob I've choose to: Transmit whole content.
What do I have to do if I want to pass this variable to a child?
Bye, Chris
Anonymous
Not applicable
Author

The globalMap instance is specific to a job, transmitting the context to a child job wont changes this.
If you intent to transmit a variable to child job, use the context then, it should be straitforward.
Anonymous
Not applicable
Author

Hello,
Existing two way to manage variable and parameter in a talend job.
1) globalMap is used to set variable in a Job, it's a hashmap
2) context var is used to set parameters
So, to achieve your goal,
1) you need to create context var in your childjob
2) With the tRunJob, use the context param tab, create a row, select the childjob context var in the first column, and set your expresion in the second one : globalMap.get("MyVar")
the transmit whole context checkbox is only for to transmit value of context var with same name from fatherjob to childjob.
Anonymous
Not applicable
Author

Eventually I got it .. I tried so hard to set a context in my fatherjob, I didn't get the idea to setup a context in the childjob! 0683p000009MPcz.png
Thank you for your help! 0683p000009MACn.png
_AnonymousUser
Specialist III
Specialist III

Hi,
How Can I share the global map between father an son job. I see that it's possible using context. In fact I have lots of parameters , so It will be hard to create a context variable for each parameter.
Thanks for your replay
James
sbxr
Contributor III
Contributor III

How to do it for long data dype

PhilHibbs
Creator II
Creator II

https://www.talendbyexample.com/talend-returning-values-from-subjobs.html

 

This is a technique for passing data down into, and back up from, child jobs. We use it a lot. We have a joblet that checks to see if context.sharedMap is initialized, and if not, creates a new ConcurrentHashMap. This joblet is placed at the start of every job that uses the context.sharedMap mechanism.