Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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.
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:
I try to print out the globalMap and it display the correct value:
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
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
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
Works like a charm. Thank you sir. I wonder why the flow should be this way
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.