How to assign value from tMAP column to global variable ?

One Star

How to assign value from tMAP column to global variable ?

Hi,
I am trying to assign the parsed string from tMAP as file name but getting null as output, How can I fix this issue ?

File_Name = "C:/users/Milind/ACARS/"+(String)globalMap.get("fltnum")+TalendDate.formatDate("yyyyMMddHHmmss", new Date()) + ".xls"
where fltnum is defined as VAR in the tMAP !
Thanks,
Milind
One Star

Re: How to assign value from tMAP column to global variable ?

Hi Milind,
if you define fltnum as variable in the tMap, use Var.fltnum instead of globalMap.
If this will not work for you a screen shot and some more information about your data would be good.
Bye
Volker
One Star

Re: How to assign value from tMAP column to global variable ?

Thanks Volker,
I tried to use
"C:/users/Milind/ACARS/output/"+Var.fltnum+TalendDate.formatDate("yyyyMMddHHmmss", new Date()) + ".dt2" instead of
"C:/users/Milind/ACARS/output/"+(String)globalMap.get("SP7.fltnum")+TalendDate.formatDate("yyyyMMddHHmmss", new Date()) + ".dt2"
and I am getting the error
Var cannot be resolved !
Additing prntscrns here (not sure how it works .. but I am using image upload and after submit its not showing up)
Thanks,
Milind
One Star

Re: How to assign value from tMAP column to global variable ?

Hi Milind,
a screen shot would be very valuable. You should care about size (pixel and memory). You could see the server defined limits in the "Post reply" -form.
Bye
Volker
One Star

Re: How to assign value from tMAP column to global variable ?

Thanks for the Tip, Added the screenshots !
Milind
One Star

Re: How to assign value from tMAP column to global variable ?

Hi Milind,
now I got it. If you define a variable inside a tMap it is only visible to this tMap. If you need to store a value for later use, You should use a context variable for this. So define a context variable, add before your tMap where you defined the actual var a tJavaRow. In tJavaRow press the button "generate code" to generate the mapping from in to out for all of your metadada and add the following code as additional line:
context.fltnum= input_row.fltnum_new;

Now you could change the string for creating the file name to:
"C:/users/Milind/ACARS/output/"+context.fltnum+TalendDate.formatDate("yyyyMMddHHmmss", new Date()) + ".dt2"

Bye
Volker
One Star

Re: How to assign value from tMAP column to global variable ?

Thanks Volker, This is what I did
1. Defined a context variable fltnum
2. In Map created another output set_fltnum and assigned it to tJavaRow
3. In tJavaRow the code is context.fltnum = input_row.fltnum;
4. In TFiledelimited used filename =
"C:/users/Milind/ACARS/output/"+context.fltnum+TalendDate.formatDate("yyyyMMddHHmmss", new Date()) + ".dt2"
its still outputting filename as null+timestamp".dt2
I know I am doing something wrong but not sure what is it ?
Employee

Re: How to assign value from tMAP column to global variable ?

Set your output "set_fltnum" as first output into the tMap and it should work.
Instead of use context variable you could set a new variable into the globalMap:
globalMap.put("fltnum", myValue)

Then get it by:
globalMap.get("fltnum")

It's just more verbose, I hope we will improve the globalMap syntax soon.
One Star

Re: How to assign value from tMAP column to global variable ?

Thanks to clarify my solution.
Milind: sorry, my explanation was not clear. You should add the tJavaRow in your stream (not as additional output from tMap). If you use a additional output this should work if you ensure it is processed first. So this output must be upside from your main stream in tMap.
Bye
Volker
One Star

Re: How to assign value from tMAP column to global variable ?

Thanks for the suggestion, Again not sure what am I doing wrong .. still same results
One Star

Re: How to assign value from tMAP column to global variable ?

Hi Milind,
try to use a tJavaRow. Add the component between SP7 and SP8 tMap.
Bye
Volker
Employee

Re: How to assign value from tMAP column to global variable ?

Your screenshot http://www.talendforge.org/forum/postgallery.php?pid=22837&filename=scr_13.JPG seems to be good except you have to set your "set_fltnum" table as first table.
Or do the proposition of Volker.
One Star

Re: How to assign value from tMAP column to global variable ?

Thanks a lot for all the help I tried both the things suggested by you .. still there are some issues still producting the same output filename that starts with null.
One Star

Re: How to assign value from tMAP column to global variable ?

Hi Milind,
sorry. You are right your job cant work. Now, after looking at all screens again and again, I see that I missed the primary point:
The value in the context variable is correct. But you cant use it inside the filename. The file is opened before your data is processed and at this time the variable is null.
So the question is: Do you have different values (and would like to create a file for each line / a group of lines) or do you have only one value.
Only one value: You must process your input two times. In the first step just extract the context variable. In the second process your data.
One file per row: Use tFlowToIterate
One file per group. A little bit more complex...
Sorry again that I missed this point.
Bye
Volker
One Star

Re: How to assign value from tMAP column to global variable ?

Hi Milind,
for every row one file?
Do the following:
Add before your file output component the following block:
tMap_8 --> tFlowToIterate --> tIterateToFlow --> tFileOutputDelimited
In tFlowToIterate use default settings.
In tIterateToFlow you have to set all your columns of you metadat from tMap_8 again. So for each column use the following code: (Type)globalMap.get("EXCL_OP1.columnName). Replace Type and columnName with the correct values.
Use the same notation for your filename.
Bye
Volker
One Star

Re: How to assign value from tMAP column to global variable ?

At last .. was able to succefullu generate the filename as required .. introduced tflowtoiterated between tMAp8 and Outputflie as per your suggestions and shown here
http://www.talendforge.org/forum/viewtopic.php?id=5827
Thanks a lot Volker, Shong and amaumont !
Milind
One Star

Re: How to assign value from tMAP column to global variable ?

Hi Milind,
you are welcome.
Bye
Volker
One Star

Re: How to assign value from tMAP column to global variable ?

Hi Milind,
The value in the context variable is correct. But you cant use it inside the filename. The file is opened before your data is processed and at this time the variable is null.
So the question is: Do you have different values (and would like to create a file for each line / a group of lines) or do you have only one value.
Only one value: You must process your input two times. In the first step just extract the context variable. In the second process your data.
Volker

Hi Volker, as you can see this is my first post (newbie status)
I have a similar task as this thread and it works well sort off.... i need only 1 csv file to be created using the Year_Month field from row1. I used your tip (*thanks) for creating a loop on the input file so that the second time it runs i dnt have the "null" but the actual value of row1.year_month.
i added a twaitforfile so that i can get the correct filename to upload using FTP and then i move this file to a done folder.
is there any way i can improve on this design?
One Star

Re: How to assign value from tMAP column to global variable ?

Hi,
welcome in the forum!
First: Are you sure your job is working? I think using a function code in context definition wouldn't work. But I may be wrong...
So you need a file as output with a name you will get as input from the data you got from your input file?
Bye
Volker
One Star

Re: How to assign value from tMAP column to global variable ?

yup thats correct.
One Star

Re: How to assign value from tMAP column to global variable ?

Hi,
I would suggest to read your file twice. First only to extract the filename (and store it into a context variable), than run an subjob (with onSubJobOk) which used the context variable to create the file.
Bye
Volker
One Star

Re: How to assign value from tMAP column to global variable ?

thanks Volker, got it and it works.
One Star

Re: How to assign value from tMAP column to global variable ?

You are welcome.
One Star

Re: How to assign value from tMAP column to global variable ?

 
One Star

Re: How to assign value from tMAP column to global variable ?

How to define the RecordType Id in Tmap by using GlobalMap.get function ?
My Record Type Id value is "Person_Customer"