google apps script - How can I pass a function to run to a function? -
i have check weather property exists before can run function listed in add-on menu google spreadsheet. rather creating copy of same check each function create single function can pass function run parameter. how can this?
below non functioning test code, may idea.
function testrun(){ //in practicality add-on menu test1check('test1()'); } function test1(){ logger.log("function ran"); } function test1check(functiontorun){ var labels = propertiesservice.getdocumentproperties().getproperty('labels'); var ui = spreadsheetapp.getui(); // same variations. if (!labels) { var result = ui.alert( 'you have not yet set page gclassfolders', 'would now?', ui.buttonset.yes_no); // process user's response. if (result == ui.button.yes) { // user clicked "yes". setupgcf(); } } else { functiontorun; } }
i had remove () parameter sent, , add () variable in function.
function testrun(){ test1check(test1); } function test1(){ logger.log("function ran"); } function test1check(functiontorun){ var labels = propertiesservice.getdocumentproperties().getproperty('labels'); var ui = spreadsheetapp.getui(); // same variations. if (!labels) { var result = ui.alert( 'you have not yet set page gclassfolders', 'would now?', ui.buttonset.yes_no); // process user's response. if (result == ui.button.yes) { // user clicked "yes". setupgcf(); } } else { functiontorun(); } }
Comments
Post a Comment