Code Coca

How to get parameters value in google app script

To get parameters in Google Apps Script, you can use the doGet() or doPost() function, which are called when your script is accessed via a GET or POST request.

Here's an example of how to get parameters from a GET request:

App Script
function doGet(e) {
var param1 = e.parameter.param1;
var param2 = e.parameter.param2;
// Do something with the parameters
}

In this example, we're using the doGet() function, which takes a single parameter (e) that contains information about the request.

To get the parameters, we access the parameter property of the e object and use the parameter names as keys to retrieve their values. In this case, we're assuming that the parameters are named param1 and param2.

You can also get parameters from a POST request using the doPost() function:

App Script
function doPost(e) {
var param1 = e.parameter.param1;
var param2 = e.parameter.param2;
// Do something with the parameters
}

The main difference here is that we're using the parameters property of the e object instead of parameter. The parameters property contains an array of values for each parameter, which is why we're not using keys to retrieve the values.

No comments:

Post a Comment