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

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] tContextLoad fills null values

Hi guys,
I was like 5 hours googling and searching that on forums (ask is the last option):

I have a context where I have a few variables and I want to fill them with a  properties file when job runs.
I have got a "tFileInputDelimiter" joined to a "tContextLoad" with the "Print operations" checkbox checked for debug reasons. Where I run the job the execution console shows like the subjob worked and the variables filled, but, when I use anyone of them, it returns a null value.
I have got a tJava to show the value with:

System.out.println((globalMap.get("NUM_CONNS")));


I am a very newbie in this tool and that can be a newbie problem too, but I was a lot of hours searching for it.
I am using Talend 5.4.1 version.
Hope you can help me.
Thank you.

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

I can't tell if that is a list of context variables in your job OR a list of context variables in a context group. Can you take a screenshot of your job with the context tab in view. If your context variable exists in your job, the code to print to the output should work.

Another thing you can try is to type "context." (without the quotes) in your tJava and hit ctrl+space. This will show you a list of autocomplete options. Your available context variables will be in that list.

View solution in original post

12 Replies
Anonymous
Not applicable
Author

You are referring to a globalMap variable in your example code. These are not context variables. I am assuming your context variable is called "NUM_CONNS". If that is the case, you should test your context variables using the below code...

System.out.println(context.NUM_CONNS);



As a small point about your example code. GlobalMap variables will store your variable as an Object. You need to identify its Class before you can read it. So, if you had a globalMap variable called "NUM_CONNS" that was a String, it would have to be used as below..

System.out.println(((String)globalMap.get("NUM_CONNS")));
Anonymous
Not applicable
Author

Hello rhall_2.0 and thank for your reply.
I changed the code of the tJava to 
System.out.println(((String)globalMap.get("NUM_CONNS")));


But the return value is the same: "null".

PD: I'm trying to post  an image but it appears as the broken icon...

This is my output:
Starting job MAIN at 14:08 21/04/2016.
[statistics] connecting to socket on port 3871
[statistics] connected
tContextLoad_1 set key "NUM_CONNS" with value "2"
tContextLoad_1 set key "dbnameCONN1" with value "MDB"
tContextLoad_1 set key "dbnameCONN2" with value "MBD"
tContextLoad_1 set key "dbnameCONN3" with value ""
tContextLoad_1 set key "dbnameCONN4" with value ""
tContextLoad_1 set key "dbnameCONN5" with value ""
tContextLoad_1 set key "hostCONN1" with value "OK"
tContextLoad_1 set key "hostCONN2" with value "OK2"
tContextLoad_1 set key "hostCONN3" with value ""
tContextLoad_1 set key "hostCONN4" with value ""
tContextLoad_1 set key "hostCONN5" with value ""
tContextLoad_1 set key "passCONN1" with value "admin"
tContextLoad_1 set key "passCONN2" with value "admin"
tContextLoad_1 set key "passCONN3" with value ""
tContextLoad_1 set key "passCONN4" with value ""
tContextLoad_1 set key "passCONN5" with value ""
tContextLoad_1 set key "portCONN1" with value "1233"
tContextLoad_1 set key "portCONN2" with value "1233"
tContextLoad_1 set key "portCONN3" with value ""
tContextLoad_1 set key "portCONN4" with value ""
tContextLoad_1 set key "portCONN5" with value ""
tContextLoad_1 set key "schemaCONN1" with value "TEST1"
tContextLoad_1 set key "schemaCONN2" with value "TESTMASTER"
tContextLoad_1 set key "schemaCONN3" with value ""
tContextLoad_1 set key "schemaCONN4" with value ""
tContextLoad_1 set key "schemaCONN5" with value ""
tContextLoad_1 set key "userCONN1" with value "TEST01"
tContextLoad_1 set key "userCONN2" with value "TESTMASTER"
tContextLoad_1 set key "userCONN3" with value ""
tContextLoad_1 set key "userCONN4" with value ""
tContextLoad_1 set key "userCONN5" with value ""
null
[statistics] disconnected
Job MAIN ended at 14:08 21/04/2016. [exit code=0]
Anonymous
Not applicable
Author

You missed the first part of what I said. Your code should read....

System.out.println(context.NUM_CONNS);

Context variables are used with a prefix of "context." then the variable name. So yours would be context.NUM_CONNS.
Anonymous
Not applicable
Author

Ok, I changed the java to:
System.out.println((globalMap.get("NUM_CONNS")));

When I run it, it shows an pop up window: NUM_CONNS cannot be resolved or is not a field.

Is maybe a problem in the defined variables in the context?
Anonymous
Not applicable
Author

1) Get an empty notepad.
2) Paste my code example on the top line.
3) Paste your code example underneath.
4) Now compare, letter for letter and see if you can see what is wrong.
Anonymous
Not applicable
Author

Oh, excuse me, I copied the other code but the code I executed before was:
System.out.println(context.NUM_CONNS);


It's a copy-paste of your code and it shows the pop-up windows:  NUM_CONNS cannot be resolved or is not a field.


The prompt:

Starting job MAIN at 16:53 21/04/2016.
[statistics] connecting to socket on port 3781
[statistics] connected
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
NUM_CONNS cannot be resolved or is not a field

at chh_stats_checker.main_0_1.MAIN.tJava_1Process(MAIN.java:1109)
at chh_stats_checker.main_0_1.MAIN.tFileInputDelimited_1Process(MAIN.java:1023)
at chh_stats_checker.main_0_1.MAIN.tChronometerStart_1Process(MAIN.java:550)
at chh_stats_checker.main_0_1.MAIN.tPrejob_1Process(MAIN.java:441)
at chh_stats_checker.main_0_1.MAIN.runJobInTOS(MAIN.java:1459)
at chh_stats_checker.main_0_1.MAIN.main(MAIN.java:1326)
tContextLoad_1 set key "NUM_CONNS" with value "2"
tContextLoad_1 set key "dbnameCONN1" with value "mbd"
tContextLoad_1 set key "dbnameCONN2" with value "mbd"
tContextLoad_1 set key "dbnameCONN3" with value ""
tContextLoad_1 set key "dbnameCONN4" with value ""
tContextLoad_1 set key "dbnameCONN5" with value ""
tContextLoad_1 set key "hostCONN1" with value "192.168.0.1"
tContextLoad_1 set key "hostCONN2" with value "192.168.0.1"
tContextLoad_1 set key "hostCONN3" with value ""
tContextLoad_1 set key "hostCONN4" with value ""
tContextLoad_1 set key "hostCONN5" with value ""
tContextLoad_1 set key "passCONN1" with value "1234"
tContextLoad_1 set key "passCONN2" with value "1234"
tContextLoad_1 set key "passCONN3" with value ""
tContextLoad_1 set key "passCONN4" with value ""
tContextLoad_1 set key "passCONN5" with value ""
tContextLoad_1 set key "portCONN1" with value "1521"
tContextLoad_1 set key "portCONN2" with value "1521"
tContextLoad_1 set key "portCONN3" with value ""
tContextLoad_1 set key "portCONN4" with value ""
tContextLoad_1 set key "portCONN5" with value ""
tContextLoad_1 set key "schemaCONN1" with value "CONN1"
tContextLoad_1 set key "schemaCONN2" with value "MASTER"
tContextLoad_1 set key "schemaCONN3" with value ""
tContextLoad_1 set key "schemaCONN4" with value ""
tContextLoad_1 set key "schemaCONN5" with value ""
tContextLoad_1 set key "userCONN1" with value "CONN1"
tContextLoad_1 set key "userCONN2" with value "MASTER"
tContextLoad_1 set key "userCONN3" with value ""
tContextLoad_1 set key "userCONN4" with value ""
tContextLoad_1 set key "userCONN5" with value ""
[statistics] disconnected
[statistics] disconnected
[statistics] disconnected
Job MAIN ended at 16:53 21/04/2016. [exit code=1]
Anonymous
Not applicable
Author

Have you actually created a NUM_CONNS context variable for this job? Can you take a screenshot of your context tab and post it?
Anonymous
Not applicable
Author

The system don't allow me to post any image, don't know why...

I uploaded it to img.ur :

imgur.com/Oiqbf07
Anonymous
Not applicable
Author

I can't tell if that is a list of context variables in your job OR a list of context variables in a context group. Can you take a screenshot of your job with the context tab in view. If your context variable exists in your job, the code to print to the output should work.

Another thing you can try is to type "context." (without the quotes) in your tJava and hit ctrl+space. This will show you a list of autocomplete options. Your available context variables will be in that list.