How to define global variable in Google Apps Script

后端 未结 6 2030
梦如初夏
梦如初夏 2020-11-30 03:23

I see most examples from Google is they use only functions in a single giant script.

e.g. https://developers.google.com/apps-script/quickstart/macros

But in

6条回答
  •  离开以前
    2020-11-30 04:17

    I'm using a workaround by returning a function with an object of my global variables:

    function globalVariables(){
      var variables = {
        sheetName: 'Sheet1',
        variable1: 1,
        variable2: 2
      };
      return variables;
    }
    
    function functionThatUsesVariable (){
      var sheet =   SpreadsheetApp.getActiveSpreadsheet().getSheetByName(globalVariables().sheetName);
    }
    

提交回复
热议问题