As a user often exports more than one time, it is handy to let the system create unique filenames.
Because otherwise the second export attempt will fail when trying to export with the same filename, while the first Excel file is open in Excel.
The reason to include also milliseconds is that the user will be able to export twice in the same minute, without producing the same file name.
- Code: Select all
/**
* Returns a unique filename like sFileName_7.3.2017_1202.238
*
* @author Gary, Bernd
* @param {String} sFileName
* @returns {String}
* @public
* @properties={typeid:24,uuid:"C5F48A7D-5E83-4559-815E-06FC9C31FF3A"}
*/
function getUniqueFilename(sFileName) {
var
sExportPath = "",
sFilePath = "",
dDate = new Date(),
iMonth = dDate.getMonth() + 1;
// If the user has set a standard output path, then take that
if (scopes.utils.stringHasContent(_to_employee$currentpersonid.e_standard_output_path)) {
sExportPath = _to_employee$currentpersonid.e_standard_output_path;
} else {
sExportPath = 'c:\\tmp';
}
sFilePath =
sExportPath + '\\' + sFileName + '_' +
dDate.getDate().toString() + '.' +
iMonth.toString() + '.' +
dDate.getFullYear().toString() + '_' +
(dDate.getHours().toString().length === 1 ? '0' : '') + dDate.getHours().toString() +
(dDate.getMinutes().toString().length === 1 ? '0' : '') + dDate.getMinutes().toString() + '.' +
dDate.getMilliseconds().toString()
return sFilePath;
}