In my spreadsheet, I have inserted 35 project in GAS to generate google doc from the same sheet with the placeholder present in the docs.
The script takes the fields from each row in the sheet the script is contained in and using a Google Doc template (identified by TEMPLATE_ID) creates a PDF doc. The fields replace the place-holders in the template. The place-holders are identified by having a % either side, e.g. %Name%. It is invoked by the “Create PDFs” menu.
Naturally I have created a project for each Google Doc template (because I need 35 different doc from 35 different templates) and so in my sheet i have about 35 custom voice in menu that activate each script. Sometimes some scripts not appears all together and so I must to reload the sheet to find the script I need.
Why? There is a way to avoid this?
The script is this:
var TEMPLATE_ID = 'xxxxxxxx';
var PDF_FILE_NAME = '';
var RESULTS_FOLDER_ID = 'xxxxxxx';
var SENT_COLUMN_NAME = 'Date Sent';
var FILE_NAME_COLUMN_NAME = 'File Name';
var EMAIL_COLUMN_NAME = 'Email';
var DATE_FORMAT = 'yyyy/MM/dd';
var DATE_TIME_FORMAT = 'yyyy/MM/dd HH:mm:ss';
function sendMultiplePdfs() {
var ui = SpreadsheetApp.getUi();
if (TEMPLATE_ID === '') {
throw new Error('TEMPLATE_ID needs to be defined in Code.gs');
return;
}
var templateFile = DriveApp.getFileById(TEMPLATE_ID);
var activeSheet = SpreadsheetApp.getActiveSheet();
var ranges = activeSheet.getActiveRangeList().getRanges();
var activeRows = [];
ranges.forEach(function(range) {
activeRows.push(range.getValues());
})
Update:
Solved by replacing the Template ID taking the value dynamically from a cell:
var ss = SpreadsheetApp.openById("ID_OF_THE_SS").getSheetByName("SHEET_NAME");
var TEMPLATE_ID = ss.getRange("RANGE_OF_THE_ID").getValue();