[resolved] t_Java and setting a global variable

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!

2019 GARNER 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

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch