Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
Labels (2)
24 Replies
Anonymous
Not applicable
Author

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

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.
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

At last .. was able to succefullu generate the filename as required .. introduced tflowtoiterated between tMAp8 and Outputflie as per your suggestions and shown here
https://community.talend.com/t5/Design-and-Development/resolved-How-to-use-Flowtoiterate/td-p/95069
Thanks a lot Volker, Shong and amaumont !
Milind
Anonymous
Not applicable
Author

Hi Milind,
you are welcome.
Bye
Volker
Anonymous
Not applicable
Author

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?
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

yup thats correct.