Context Load from text file - Can't read the loaded variables

Seven Stars

Context Load from text file - Can't read the loaded variables

So I created this quick job and strangely, even after getting confirmation that the variables have been loaded, I can't seem to read the variables using context.<var_name>. What am I doing wrong?

 

The input file has just one variable 'temp_var' with value set to 'passed' (temp_var=passed). While loading the job, I also see the info in the talend log window (tContextLoad_2 set key "test_var" with value "passed"). Further, I can use the context.containsKey("test_var") construct and it yields 'true' in the Java Node. But the moment I try to run the following command, it fails:

 

System.out.println("Value of var test_var read from context " + context.test_var);

 

Kindly help.

 

Screenshot from 2018-08-10 16-49-20.png


Accepted Solutions
Highlighted
Seven Stars

Re: Context Load from text file - Can't read the loaded variables

So I saw the source code of another job with context variables and found that talend internally manages the context variables using the getProperty method. Used that information and it all worked fine.

System.out.println("Value of var test_var read from context " + (String) context.getProperty("test_var"));

View solution in original post


All Replies
Highlighted
Seven Stars

Re: Context Load from text file - Can't read the loaded variables

So I saw the source code of another job with context variables and found that talend internally manages the context variables using the getProperty method. Used that information and it all worked fine.

System.out.println("Value of var test_var read from context " + (String) context.getProperty("test_var"));

View solution in original post

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog