Add default values for 'Version' and 'Approved Date'

This commit is contained in:
Adam Goldsmith 2020-06-25 16:37:28 -04:00
parent 5c6b6fda02
commit e47ac06cd5

15
Code.ts
View File

@ -148,7 +148,12 @@ function generateForRow(
const source_file = DriveApp.getFileById(DocumentApp.openByUrl(link).getId());
const out_folder = DriveApp.getFolderById(OUTPUT_FOLDER_ID);
const out_name = row['Document'] + '_' + row['Version'];
const out_name =
row['Document'].getText() +
'_' +
(row['Version'].getText() || 'No Version') +
'-' +
(row['Approved Date'].getText() || 'NOT APPROVED');
// Delete old files with the same name
trashFiles(out_folder.getFilesByName(out_name));
@ -194,6 +199,14 @@ function generateForRow(
// do text replacement
Object.entries(row).forEach(([header, data]) => {
let replacement = data.getText();
if (!replacement) {
// default values when empty
if (header === 'Version') {
replacement = 'No Version';
} else if (header === 'Approved Date') {
replacement = 'NOT APPROVED';
}
}
out_doc.getBody().replaceText(`{{${header}}}`, replacement);
out_doc.getHeader().replaceText(`{{${header}}}`, replacement);
out_doc.getFooter().replaceText(`{{${header}}}`, replacement);