How to pass a parameter to html?

前端 未结 5 1715
小鲜肉
小鲜肉 2020-11-28 13:01

I have a script that uses the file picker but I need to pass a specific parameter which is called userId and is kept as a global variable in the calling script.

5条回答
  •  青春惊慌失措
    2020-11-28 13:49

    In your code:

    function scriptUser_(userId) {
      if (userId !== undefined)
        sUserId = userId; // Global variable
      try { return sUserId; } catch (e) { return undefined; }
    }
    

    You are assigning a value to the global variable named sUserId. But, then when you try to retrieve it, nothing is there. Global variables loose their value as soon as the current instance of the code bring run is completed. Global variable don't persist their values.

    You'll need to use the Properties Service to store the value. Or you could use the Cache service. If you want the value of the user id to expire after some time, use cache service.

提交回复
热议问题