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


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.

Popular posts from this blog

List of Kim Possible characters

Audio Livestreaming with Python & Flask

NSwag: Generate C# Client from multiple Versions of an API