Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
ZulFast
Contributor
Contributor

Using globalMap into file output name

Dear Community,

I'm new with talend and appreciate you could help me on this. I want to extract files from .csv and output as .csv with custom name variable.

0695b00000kYhjfAAC.png

The file name output is depending on the input file. For example the input file is file_1_2011. The output file should be file_1_20201130. The date should be the last date of the month. On tjava i have create a script for this. I use globalMap.put to assign the final file name and call it in tFileOutputDelimited. The issue now is the first file name comes out great however the second file become null. As below:

0695b00000kYhkEAAS.png

I try to print out the globalMap and it display the correct value:

0695b00000kYhkOAAS.png

Please find my tjava code as below:

System.out.println("Processing file: "+ ((String)globalMap.get("tFileList_1_CURRENT_FILE")));

String file_process = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));

String file_process_F = file_process.substring(0, 23);

String file_date = file_process.substring(23, 27);

String year = StringHandling.LEFT(file_date, 2);

String month = StringHandling.RIGHT(file_date, 2);

String year_F;

if (year.contains("20")){

year_F = "2020";

}else if (year.contains("21")){

year_F = "2021";

}else {

year_F = "00";

}

String testDate = year_F + "/" + month + "/" + "01";  

Date test = TalendDate.getLastDayOfMonth(TalendDate.parseDate("yyyy/MM/dd", testDate));

String FinalDate = TalendDate.formatDate("yyyyMMdd", test) + ".csv";

String Output = file_process_F + FinalDate;

globalMap.put("Output", Output);

System.out.println(((String)globalMap.get("Output")));

Sorry if my scripting is bad. Appreciate if anyone can help

Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi

Move tJava to be the first component before tFileInputDelimited, eg:

tFileList--iterate--tJava--oncomponentOK--tFileInputDelimited.......

 

Please try and let me know if it works.

 

Regards

Shong

View solution in original post

3 Replies
Anonymous
Not applicable

Hi

Move tJava to be the first component before tFileInputDelimited, eg:

tFileList--iterate--tJava--oncomponentOK--tFileInputDelimited.......

 

Please try and let me know if it works.

 

Regards

Shong

ZulFast
Contributor
Contributor
Author

Works like a charm. Thank you sir. I wonder why the flow should be this way

Anonymous
Not applicable

The variable should be initialized before it is used. If tJava component is in another iterate flow, there is no guarantee that it will be executed before tFileOutputDelimited.