Lookup template ID from name instead of getting directly from sheet

This commit is contained in:
Adam Goldsmith 2020-06-22 11:46:56 -04:00
parent e158e31bf1
commit b7a301ba78

13
Code.ts
View File

@ -1,3 +1,7 @@
const DOCUMENT_TEMPLATE_IDS = {
Certification: '1V0uMuM80BGpjpdt1AmuzlU97tDI_u-y2rOfdl4tkqmc',
};
const OUTPUT_FOLDER_ID = '1ROyJXk-QANTHM6Jiw0ne3EQiR1f2UsLr'; const OUTPUT_FOLDER_ID = '1ROyJXk-QANTHM6Jiw0ne3EQiR1f2UsLr';
function onOpen() { function onOpen() {
@ -80,7 +84,14 @@ function generateForRow(
) { ) {
const row = spreadsheetRowToObject(spreadsheet.getActiveSheet(), row_num); const row = spreadsheetRowToObject(spreadsheet.getActiveSheet(), row_num);
const template_doc = DocumentApp.openById(row['Template ID']); if (!(row['Document Type'] in DOCUMENT_TEMPLATE_IDS))
throw new Error(`${row['Document Type']} is not a valid type of document!`);
const template_doc = DocumentApp.openById(
DOCUMENT_TEMPLATE_IDS[
row['Document Type'] as keyof typeof DOCUMENT_TEMPLATE_IDS
]
);
const source_file = DriveApp.getFileById(row['Document ID']); const source_file = DriveApp.getFileById(row['Document ID']);
const out_folder = DriveApp.getFolderById(OUTPUT_FOLDER_ID); const out_folder = DriveApp.getFolderById(OUTPUT_FOLDER_ID);