Pass Array into Apps Script Function

Hi There,

I saw a thread about trying to pass an array into an apps script function from appsheet through bot automation and the workaround was to have a bot dump the data to be passed into a JSON file and then operate on that file once inside the Apps Script function.

Is there no other good work around to this? 

I have also looked at passing the data as a string via the SELECT function and then splitting the string once inside the function but that is also quite ugly.

Thanks.

Solved Solved
0 2 656
1 ACCEPTED SOLUTION

What is the purpose of submitting an array of values to the App Script?  What does the App Script do with the Array?

First, AppSheet CAN pass multiple arguments to the App Script.  If you have a known number of values in your array then this might be the way to go.

Speaking generally, the way to submit an array of values from one service to another is through some text format.  In that sense JSON is the go to method today because of the standardization around how to parse JSON strings.   Google App Script, if that is what we are referring to here, does have built in JSON parsing functions.

For your use case, if you must pass an array, there are three other methods:

1)  As you mentioned, you could construct a string with the values and then deconstruct it in the script.  This was the OLD way of passing arrays before JSON.

2)  You could "park" your array values in a utility datasource table and then have your script connect to that datasource and read the values from that utility table.

3)  If the intention is to iterate over the array of values and produce a result on each iteration,  then you could construct the script to process a single value and return that result.  Then build the AppSheet automation to "loop" through the array of values, calling the script each time and saving the result for whatever other purposes you might have for it.

I hope this helps!


View solution in original post

2 REPLIES 2

What is the purpose of submitting an array of values to the App Script?  What does the App Script do with the Array?

First, AppSheet CAN pass multiple arguments to the App Script.  If you have a known number of values in your array then this might be the way to go.

Speaking generally, the way to submit an array of values from one service to another is through some text format.  In that sense JSON is the go to method today because of the standardization around how to parse JSON strings.   Google App Script, if that is what we are referring to here, does have built in JSON parsing functions.

For your use case, if you must pass an array, there are three other methods:

1)  As you mentioned, you could construct a string with the values and then deconstruct it in the script.  This was the OLD way of passing arrays before JSON.

2)  You could "park" your array values in a utility datasource table and then have your script connect to that datasource and read the values from that utility table.

3)  If the intention is to iterate over the array of values and produce a result on each iteration,  then you could construct the script to process a single value and return that result.  Then build the AppSheet automation to "loop" through the array of values, calling the script each time and saving the result for whatever other purposes you might have for it.

I hope this helps!


Got it thanks a bunch for the answer!  I'll continue to use the JSON method for now.  Cheers mate.

Top Labels in this Space