How to Loop through Values in Google Sheet while creating a Trigger?

Multi tool use
Multi tool use


How to Loop through Values in Google Sheet while creating a Trigger?



I have Google Apps Script Code in the following format:


var key = "ID of the Sheet";

var key1 = "ID of the Sheet";

function createTriggers() {

ScriptApp.newTrigger('filter')
.forSpreadsheet(key)
.onEdit()
.create();
}

function createTriggers() {

ScriptApp.newTrigger('filter')
.forSpreadsheet(key1)
.onEdit()
.create();
}



How to loop through all keys (key, key1, key2...) and create triggers via a single function?





Pretty broad question. Can you be more specific? What are you trying to accomplish?
– Cooper
3 mins ago





I want to create a trigger for multiple sheets in a standalone script, as of now, I have to create a separate function for each trigger as seen in the above example. Need a way to loop through keys and create triggers via a single function.
– dc09
1 min ago




1 Answer
1



Something like this:


function createTriggers() {
var keys = [
'key1',
'key2'
]
for (var i = 0; i < keys.length; i++) {
ScriptApp.newTrigger('filter')
.forSpreadsheet(keys[i])
.onEdit()
.create();
}
}






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

VQpckIzw3V hq,bIouC1FFeU,GqhUX6QPvY6QvqGUscf65,7S0v32I8d
FTY7CIG2mfi5TmM9XvXqujTHASVfDItTryMSFLDT9c3 lHw

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

Audio Livestreaming with Python & Flask