Four Stars

globalMap.put() not working in tJavaRow

Hi,

I try to change a globalMap variable in tJavaRow at every row (with a test).

but my problem is that it doesn't change anything when I use globalMap.put("CPBox",input_row.CPBox)...

I'm beginner and i think i don't use tSetGlobalVar in the right place...

Here is my job :

TalendtJavaRowExemple.png

 

In my .csv, the output "CpBox" is the default variable "myValue" of the tSetGlobalVar... 

Someone can help me ? ^^

 

Thank you !

1 ACCEPTED SOLUTION

Accepted Solutions
Fifteen Stars

Re: globalMap.put() not working in tJavaRow

In your tJavaRow you are creating a new HashMap called "globalMapp". You do not need to create the "globalMap" HashMap, it is created by Talend for you. It also only has one "p".

 

In your tMap you are using the correct globalMap. However this will have no data since you were adding it to the one you created.

Rilhia Solutions
7 REPLIES
Thirteen Stars TRF
Thirteen Stars

Re: globalMap.put() not working in tJavaRow

As tSetGlobalVar starts first, you need to put your tJavaRow in a previous subjob


TRF
Four Stars

Re: globalMap.put() not working in tJavaRow

@TRF, i think I understand what you mean, but I don't see how to realize it...

Thirteen Stars TRF
Thirteen Stars

Re: globalMap.put() not working in tJavaRow

Well, maybe was not a so good idea.

What do you do in your tMap?


TRF
Four Stars

Re: globalMap.put() not working in tJavaRow

@TRF,

I make this :

TalendtMapExample.png

Here is the version simplify for test, I actually get one address per customer, and a customer can have multiple delivery addresses (depending on where the warehouse is located), but the billing address is the same each time. And it changes for each client. So I want to define the billing address as soon as CLCCLL == 0 in global variable to have access to this address for all customer records.
Because CLCCLL was 0 for the parent company, 1 for the first warehouse, 2 for the second,etc...

and CLCCLL was reset for the second customer,etc...
I don't know if I'm clear, I myself had a little trouble understanding... 

Fifteen Stars

Re: globalMap.put() not working in tJavaRow

In your tJavaRow you are creating a new HashMap called "globalMapp". You do not need to create the "globalMap" HashMap, it is created by Talend for you. It also only has one "p".

 

In your tMap you are using the correct globalMap. However this will have no data since you were adding it to the one you created.

Rilhia Solutions
Four Stars

Re: globalMap.put() not working in tJavaRow

@rhall_2_0, ok thanks, and how can i have data in the globalMap ? How can i put the data in the globalMap and use in tMap after ? ^^

Four Stars

Re: globalMap.put() not working in tJavaRow

It's work !

Finally I removed the HashMap statement, and instead of charAt(0), I put charAt(1) (java array don't start at 0?).
I finally got the result I wanted, thank you both for taking your time!