I would use a combination of workflows and the API.
Here are the steps:
The first step is to prepare a JSON payload for the API.
Start by creating a JSON Object in each row to define the columnValues for each add row mutation. This will be something like:
{
"colx": "itemID",
"qty": 7
}
You’ll need to get the actual key values to use via “Show API” on your second table
Next add a JSON Template column to take the previous column and insert it into an add row mutation. Your JSON Template should look something like this:
In the above, you add a replacement for $colvalues, and point that at the first column.
Next, you want a Query column. Target it at the same table, and apply a filter so that it only matches rows where QCRequired is checked (assuming that is a boolean column).
Now add a Lookup column that targets the JSON Template via the Query column. This will give you an array of mutations.
Finally, you need one more JSON Template column to prepare your API payload. The template should look like the following:
{
"appID": $appID,
"mutations": $mutations
}
In the above, replace $appID with your App ID, and $mutations with the Lookup column.
Next, the workflows. Because you may have as many as 500 mutations, I would recommend using a combination of a User Triggered workflow, and a Webhook Triggered workflow. The idea is that the first workflow passes the API payload to the second, and then the second adds all the rows in the background via the API. This allows you to return control to the user immediately, so they don’t have to wait while the rows are added.
So, in your User initiated workflow, all you need is a Call API or Trigger Webhook step. It should call the URL of the second workflow, and pass your JSON payload (the final template column) in the body.
In the second (webhook triggered) workflow, add the following steps:
– Query JSON, targeting the trigger body
– Call API, calling the Glide API and passing the output of the previous column.
I have used the above technique a lot, and it works really well. So give that a go. If you get stuck anywhere along the line, let me know and I’ll try to help.
Hi Darren, thanks so much this is gold! Tomorrow I will try to go through these steps (and reviewing the docs about JSON and Glide API) and see if I can wrap my head around it. Will most likely be back with questions😂 Thanks!
Hi Darren, I have started building this out but I am struggling to understand how the number of rows to be added is determined? I understand that an array of mutations is created via the Lookup/Query columns, but how does it know how many elements to add to the array?
For example: Line Items row says: Product: A, qty:9
How is the value of [qty] here passed on to determine the size of the array?
I hope my question makes sense. I am sure it is there in your description, I just would like to understand how it works
oh, no… I misunderstood your question
If Qty is 9, then you want 9 rows added, yes?
Okay, I’ll need to put my thinking cap on for that one…
Let me give it some thought and will come back to you
Yes, that’s correct Thanks so much for your help so far. I have learnt a lot already about JSON and the Glide API which I had never worked with before. Looking forward to see your ideas!
@Darren_Murphy
Could you use javascript where p1 is count and p2 is mutation string for add row?
if (p1 < 2) {return"";}
return p2.repeat(p1-1);)?
Create the two mutations in the row (one with a comma and one without) and use javascript to create the count-1 mutations. Put the two columns into an array then use join to combines the two.
Here is what it looks like with emails instead of mutations:
I think JavaScript is definitely the way to go here. I would prepare an input that represents all items that you need to be added, alongside the quantity, and then run it through JS to get the output.
Next, run an API call step and I think you’re good to go.
Thank you all! The answer I dreaded the most, “Use JavaScript” But I would like to learn and so I am happy to give this a try. I am not expecting you to write the JS for me, but in order for me to figure this out, could you please clarify or add some more details to the steps described here? @ThinhDinh
I think JavaScript is definitely the way to go here. I would prepare an input that represents all items that you need to be added, alongside the quantity, and then run it through JS to get the output.
Thank you so much for taking the time to put this together, I really appreciate it! I have now received one solution for solving it with JavaScript and one solution on how to handle it with Glide tables and Workflows. Will try both options for learning purposes. Thank you so much!