Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Proper Way to Pass JSON to a Query

Issue

I am having trouble using an array I am passing in the Google Sheets Insert Many query. I have tried using {{this.params}} and {{this.params.updatedData}}, but it is just passing the string instead of the array. Currently, I am storing the array in a store value and using {{appsmith.store.testData}} in the query, but I am looking for a better solution.

Resolution

The problem is that when using the Google Sheets Insert Many query in Appsmith, passing an array to the query is not straightforward. The solution is to pass the array as a parameter to the query using key-value syntax. This can be done by running the query like this:

New_Shipment.run({ updatedData: updatedData })

The key "updatedData" is used to pass the array to the query, and it can be accessed in the query using {{this.params.updatedData}}. This is a good practice because it separates the data from the query logic and makes the code more scalable and reusable.

Here's an example of how this could be implemented:

// JS function that creates the array and passes it to the query
function submitShipment() {
  const updatedData = [[1,2,3], [4,5,6], [7,8,9]]; // example array
  New_Shipment.run({ updatedData: updatedData });
}

// Appsmith query that uses the array parameter
{{New_Shipment.query}}
{
  "range": "Sheet1!A:C",
  "majorDimension": "ROWS",
  "values": {{this.params.updatedData}}
}

By using the key-value syntax to pass the array parameter to the query, the code is cleaner and easier to understand, and it also allows for more flexibility and reusability in the future.