Add default values for 'Version' and 'Approved Date'
This commit is contained in:
parent
5c6b6fda02
commit
e47ac06cd5
15
Code.ts
15
Code.ts
@ -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);
|
||||
|
Reference in New Issue
Block a user