I have a spreadsheet that I'm using as a template for a purchase order log. This spreadsheet has a scripted onOpen(e)
function that automatically creates a timed trigger for another function that downloads the spreadsheet as an XLS file to a specific shared drive.
The purpose of the trigger is to automate the download process so any copied spreadsheet data is not lost due to human error.
My problem is that when a user makes a copy of the template, the onOpen(e)
function will not run due to the fact that you have to manually authorize said user to run scripts for the new spreadsheet.
Is there any way to automate script authorization?
function onOpen(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ssn = ss.getId();
var ssf = DriveApp.getFileById(ssn);
var test = ss.getOwner().getEmail();
var tName = ScriptApp.getProjectTriggers();
if (test != "itadmin@company.com") {
if (tName.length > 0) {
ScriptApp.deleteTrigger(tName.pop());
}
ScriptApp.newTrigger('downloadXLS')
.timeBased()
.onWeekDay(ScriptApp.WeekDay.MONDAY)
.atHour(1)
.create();
ss.addEditor("itadmin@company.com");
ssf.setOwner("itadmin@company.com");
}
}