From b7a301ba78523891db55033b765eed0e3747f3c0 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 22 Jun 2020 11:46:56 -0400 Subject: [PATCH] Lookup template ID from name instead of getting directly from sheet --- Code.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Code.ts b/Code.ts index 1cbdd18..eb2e497 100644 --- a/Code.ts +++ b/Code.ts @@ -1,3 +1,7 @@ +const DOCUMENT_TEMPLATE_IDS = { + Certification: '1V0uMuM80BGpjpdt1AmuzlU97tDI_u-y2rOfdl4tkqmc', +}; + const OUTPUT_FOLDER_ID = '1ROyJXk-QANTHM6Jiw0ne3EQiR1f2UsLr'; function onOpen() { @@ -80,7 +84,14 @@ function generateForRow( ) { 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 out_folder = DriveApp.getFolderById(OUTPUT_FOLDER_ID);