Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi, I have the following job. I want to add the latest date in the zip file like Book1yyy_20240710 but there is an error.
Archive File : ("D:/alfy/test_talend/hasilnya/result_zip/")+((String)globalMap.get("tFileList_5_CURRENT_FILE")).replaceAll("\\.xlsx$", "").replaceAll(" \\.pptx$", "")+"_"+((Date)globalMap.get("curdate"))+".zip"
Error :
How do I get just the date without errors and do I need other components?
Hello
Use a tJava instead of tSetGlobalVar component to get the current date and format it to a string value.
String currentDate=TalendDate.formatDate("yyyyMMdd", TalendDate.getCurrentDate());
globalMap.put("currentDate",currentDate);
Use another tJava after tFileList to build the output file path, the job looks like:
tJava_1
|onsubjobok
tFlieList--iterate--tJava_2--oncompoentok--tFileArchive
on tJava_2:
String filename=((String)globalMap.get("tFileList_1_CURRENT_FILE"));
String file=filename.substring(0, filename.lastIndexOf(".")); //get the filename without extension
globalMap.put("file", file);
on tFileArchive component, set the Archive file field as:
"D:/output_file_path/"+(String)globalMap.get("file")+"_"+(String)globalMap.get("currentDate")+".zip"
Set the filemask as:
((String)globalMap.get("tFileList_1_CURRENT_FILE"));
// The tFileArchive component will archive each file to a separated zip file.
Hope it helps!
Regards
Shicong
Hello
Use a tJava instead of tSetGlobalVar component to get the current date and format it to a string value.
String currentDate=TalendDate.formatDate("yyyyMMdd", TalendDate.getCurrentDate());
globalMap.put("currentDate",currentDate);
Use another tJava after tFileList to build the output file path, the job looks like:
tJava_1
|onsubjobok
tFlieList--iterate--tJava_2--oncompoentok--tFileArchive
on tJava_2:
String filename=((String)globalMap.get("tFileList_1_CURRENT_FILE"));
String file=filename.substring(0, filename.lastIndexOf(".")); //get the filename without extension
globalMap.put("file", file);
on tFileArchive component, set the Archive file field as:
"D:/output_file_path/"+(String)globalMap.get("file")+"_"+(String)globalMap.get("currentDate")+".zip"
Set the filemask as:
((String)globalMap.get("tFileList_1_CURRENT_FILE"));
// The tFileArchive component will archive each file to a separated zip file.
Hope it helps!
Regards
Shicong
it worked, very helpful, thank you
so if we use "globalMap.put" it will automatically become a global variable without having to use the tSetGlobalVar component? and if using tSetGlobalVar component then no need to use "globalMap.put" right?
Yes, you can use 'globalMap.put' to declare a global variable without having to use the tSetGlobalVar component, this makes it easy for you to define global variables in code snippets on tJava/tJavaFlex/tJavaRow.