Five Stars

tsetglobalvar returns null for the value of output from tmap

The variable from tSetglobalvar is returning null when tried to print from tjava or used in expression of tmap.

Design and requirement:

Check for maximum ID using SQL in a table and add 1 to the max value in tmap. Get tmap output column in tsetglobalvar as variable and use this in next sub job's tmap expression. Currently this is printing null

toracleinput -> tmap -> tsetglobalvar -> On sub job OK ->tjava(System.out.println(globalMap.get("Campaign_ID"))Smiley Wink

 

1 ACCEPTED SOLUTION

Accepted Solutions
Thirteen Stars TRF
Thirteen Stars

Re: tsetglobalvar returns null for the value of output from tmap

Sorry, I didn't look carefully at the job design.

You have to replace tSetGlobalVar by tFlowToIterate to generate the global variable from the flow.

Capture.PNG

 

Then, you will have the global like this:

(Integer)globalMap.get("CAMPAIGNID")

 


TRF
7 REPLIES
Thirteen Stars TRF
Thirteen Stars

Re: tsetglobalvar returns null for the value of output from tmap

Hi,

Try this:

System.out.println(globalMap.get("Out.Campaign_ID"))

 


TRF
Five Stars

Re: tsetglobalvar returns null for the value of output from tmap

Thank you TRF. I still get the result as null

Seven Stars

Re: tsetglobalvar returns null for the value of output from tmap

The "Value" column of the tSetGlobalVar should not be pulling from a global var itself.  If all you want to do is store the output of the tMap, use

Out.CAMPAIGNID

instead of 

((Integer)globalMap.get("Out.CAMPAIGNID"))

as the value. Since you never established a value earlier for the key "Out.CAMPAIGNID" then, this will return null

Five Stars

Re: tsetglobalvar returns null for the value of output from tmap

Thanks evansdar. I just did that and it threw an error. I changed value in tsetglobalvar to Out.CampaignID

 

Exception in thread "main" java.lang.Error: Unresolved compilation problem:

Out cannot be resolved to a variable

Thirteen Stars TRF
Thirteen Stars

Re: tsetglobalvar returns null for the value of output from tmap

Sorry, I didn't look carefully at the job design.

You have to replace tSetGlobalVar by tFlowToIterate to generate the global variable from the flow.

Capture.PNG

 

Then, you will have the global like this:

(Integer)globalMap.get("CAMPAIGNID")

 


TRF
Five Stars

Re: tsetglobalvar returns null for the value of output from tmap

This works wonders. Thank you TRF. I have been struggling with this small part that is pending in my job. Can't thank you enough. have a good one.

Four Stars

Re: tsetglobalvar returns null for the value of output from tmap

Similar fault (and solution) here.  In fact three different reasons why a variable print might give a null back.  

 

To be fair Java is not my first coding language and I just copy-paste-hacked at the string part of the code to put a label on it instead of paying attention to what it actually said.   ...which is now obvious after reading the explanation above.  

 

1&2

 

WRONG (this gets a null and is the wrong type for the variable - 2 errors):

System.out.println(((String)globalMap.get("DEL: " + "tJDBCOutput_2_NB_LINE_DELETED")));

 

RIGHT: 

System.out.println(("ERR: " + (String)globalMap.get("tJDBCOutput_2_ERROR_MESSAGE")));
System.out.println(("LINE: " + (Integer)globalMap.get("tJDBCOutput_2_NB_LINE")));
System.out.println(("UPD: " + (Integer)globalMap.get("tJDBCOutput_2_NB_LINE_UPDATED")));
System.out.println(("INS: " + (Integer)globalMap.get("tJDBCOutput_2_NB_LINE_INSERTED")));
System.out.println(("DEL: " + (Integer)globalMap.get("tJDBCOutput_2_NB_LINE_DELETED")));
System.out.println(("REJ: " + (Integer)globalMap.get("tJDBCOutput_2_NB_LINE_REJECTED")));

 

Hope that helps someone who also wasn't looking properly.   

 

3

 

And one more...   Smiley Happy

 

If you get a null in an output check the number near "tJDBCOutput_2_NB_LINE_REJECTED".   If you remove and re-add the same component during refactoring your flows the number of the component may alter so e.g. what was the java output object  tJDBCOutput_1 may become tJDBCOutput_2.     The log print is then left referencing the old entry unless you update it.