Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to use context variable in another context variable

Hi, Can anyone let me know how to define/use (Is it possible?) context variable in another context variable like nested?
Let say there are 2 context variables as listed below. if you see the second variable "proj_persist" has the prefix path same as proj_home but I am not able to use like proj_persist=context.proj_home +"/persist". Is there any way to do or similar approach?
"Proj_home=/mapr/datavolume/project_name"
"proj_persist=/mapr/datavolume/project_name/persist"
Labels (2)
7 Replies
Anonymous
Not applicable
Author

you can say: -
context.proj_persist = context.proj_home + "/persist";
Anonymous
Not applicable
Author

Can that be possible while declaring the context variables?
Anonymous
Not applicable
Author

you have to pre-define your context variables.
If you're just looking for arbitrary global storage, then I'd recommend using globalMap.
I only use context for when I want to externalise values or pass parameters.
globalMap.put("proj_persist", context.proj_home + "/persist");
System.out.println(((String) globalMap.get("proj_perist")));
Anonymous
Not applicable
Author

I tried context.proj_persist = context.proj_home + "/persist" this while defining context variable using wizard. It is not recognizing context variable if I use within the value. I need these to be defined in global context it self so that all the talend big data jobs can use them. Do you have any other way to do so without writing code?
Anonymous
Not applicable
Author

You need to better explain what your end game is as it is not clear what you want.
Create a Context Group with all the variables you need.
Add it to each Job.
Set "Transmit whole Context" in each of your tRunJob if you have any.
Now, everything is global.
Anonymous
Not applicable
Author

Currently my project directory locations are defined like this in context variables.
proj_home=/mapr/datavolume/project_name/
proj_data=/mapr/datavolume/project_name/data/
proj_persist=/mapr/datavolume/project_name/data/persist/
proj_transient=/mapr/datavolume/project_name/transient/
But I want to know is there a way to re-use "context.proj_home" to define other variables in context itself.
proj_home=/mapr/datavolume/project_name/
proj_data=context.proj_home + "data/"
proj_persist=context.proj_data + "persist/"
proj_transientcontext.proj_data + "transient/"
If you look into unix scripts, we can write something like below (similar to above). I want to know whether that can be possible in defining context variables in Talend.
in UNIX
PROJ_HOME==/mapr/datavolume/project_name/
PROJ_DATA=${PROJ_HOME}/data
PROJ_PERSIST=${PROJ_DATA}/persist
Anonymous
Not applicable
Author

this is still the correct answer.
context.proj_persist = context.proj_home + "/persist;"
Create a Context Group called FileSystem.
Add all of your variables.
Add it to your Jobs.
In a tJava, set all of your variables you want, except for proj_home.
I would not, personally, do it this way; but this is the answer to your question.