3

From the documentation, https://developers.google.com/apps-script/guides/standalone

Running a standalone script

After writing a script, there are two ways to run a function from the script editor:

  • Select the Run menu, followed by the name of the function you want to execute.

  • Choose the name of the function you want to execute from the select box in the toolbar, then click ▶.

It does not tell us how to pass the parameter values to the functions I want to run.

So how could I pass the parameter values to the functions and run these functions?

Rubén
  • 34,714
  • 9
  • 70
  • 166
searain
  • 3,143
  • 6
  • 28
  • 60
  • I'm not sure whether I could understand about what you want. When you want to run a function from the same project by giving values, how about this? In the case of this script ``function run() {main("foo")}; function main(v){}``, run ``run()``. By this, ``main(v)`` can get ``"foo"`` and run. If you want to run a function from other project, how about using [scripts.run of Apps Script API](https://developers.google.com/apps-script/api/reference/rest/v1/scripts/run) or [Web Apps](https://developers.google.com/apps-script/guides/web)? These methods can give values when the function is run. – Tanaike Aug 10 '18 at 23:42
  • @Tanaike, I am coding the Google Apps Scripts for non developer to use. scripts.run will work. But still it is not very straightforward for non developer to submit the parameters in json request body. I saw a hacking solution, https://developers.google.com/apps-script/guides/bound, instead of standalone, bound the script to Google sheet. and read the "parameters values" from Google Sheet Cells. This way, the user just need to fill up or change the values of Google Sheet Cells, the values will be read into the Google Apps Script functions. – searain Aug 10 '18 at 23:57
  • I'm really sorry my comment was not useful for your situation. – Tanaike Aug 11 '18 at 00:46
  • @Tanaike, your comment is helpful. :) – searain Aug 11 '18 at 02:01
  • Thank you for the reply. If you have issues for your situation, feel free to tell me. I would like to think of the solution. – Tanaike Aug 11 '18 at 02:03

1 Answers1

5

The Google Apps Script editor Run feature doesn't offer a direct way to pass parameters to functions so we have to create a helper function to be called by this feature which in time will call the function of interest with the required parameters.

The above is the that we should do to test trigger functions that require an event object as parameter as is described on How can I test a trigger function in GAS?

Rubén
  • 34,714
  • 9
  • 70
  • 166