Is it possible to add an existing app script to a newly created googlesheet using app script? And automatically assigning it to a trigger?
For example I have a spreadsheet call spreedsheetA. Then my form will create spreedsheetB, is it possible to automatically add my app script to spreedsheetA to spreedsheetB with out copy + pasting it manually. All by using the appscript in my form.
As a workaround to what @Tanaike proposed you can use the Drive API to make the copy. Because bounded scripts are also copied when you perform a makeCopy() operation.
Steps:
Extensions > Apss Script. Take note of the ID, in the example I will call it SSA_IDfunction onOpen(e) {
SpreadsheetApp
.getUi().alert('Hi from bounded script')
}
function copySpreadSheet() {
const file = DriveApp.getFileById(SSA_ID)
const newFile = file.makeCopy(`SpreadSheetCopy_${new Date().toISOString()}`)
Logger.log(newFile.getUrl())
}
From there you can manipulate the copy and add it to an Installable Trigger, for example:
ScriptApp.newTrigger('copySpreadSheet')
.timeBased()
.everyHours(6)
.create();
newTrigger(functionName)ClockTriggerBuilderIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With