[resolved] t_Java and setting a global variable

Highlighted
One Star

[resolved] t_Java and setting a global variable

I was wondering if anyone could help me figure out why this code does not work (it executes just does not do what I want it to).
I have a tMap that sends one row to a tJava transformation. The t_Java is designed to set a global variable with the following code:
System.out.println("Value Of Input:" + setVariable.varTOP);
globalMap.put("context.rowTOP", setVariable.varTOP);
System.out.println("Value Of Input:" + setVariable.varTOP);
System.out.println("Value of Global Var: "+(Integer) globalMap.get("context.rowTOP"));
I have added the println for validation. No matter what I send as input from the tMap to the tJava equation it results in 0 being displayed by all of the println's above. I have tried to manually set the value in my tMap as 1 and it still displays 0 in the tJava. I am on talend 4.2.2.
Anyone have any ideas?
Thanks

Accepted Solutions

Re: [resolved] t_Java and setting a global variable

Hi ricepato
Connect a tjavarow to your tmap instead of a tjava.
tmap --main--> tjavarow
and using the following code in the tjavarow:
System.out.println("Value Of Input: "+input_row.varTOP);
globalMap.put("varTOP", input_row.varTOP);
System.out.println("Value Of GlobalVar: "+globalMap.get("varTOP"));

All Replies

Re: [resolved] t_Java and setting a global variable

Hi ricepato
Connect a tjavarow to your tmap instead of a tjava.
tmap --main--> tjavarow
and using the following code in the tjavarow:
System.out.println("Value Of Input: "+input_row.varTOP);
globalMap.put("varTOP", input_row.varTOP);
System.out.println("Value Of GlobalVar: "+globalMap.get("varTOP"));
One Star

Re: [resolved] t_Java and setting a global variable

Yes, just figured that out actually. Thanks for the response though!

Cloud Free Trial

Try Talend Cloud free for 30 days.

Tutorial

Introduction to Talend Open Studio for Data Integration.

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.