Control query for each item in listView

Hey team,

I need to trigger a control query for each item in my listView component upon a form submit.

In the screenshot below it's for each of the invoice line items, grouped in a listView component as part of the broader form. Ideally it's on the form submit that it triggers the query for each of the list items.

Any ideas on where to start to trigger this?

Thanks in advance!

Welcome to the community!

The listview inside the form should present itself as a form item like any other so you can loop through each line item within it as part of a "run script" handler or a JS Query.

ie. on the form submit handler you can run an inline "run script" or you could call a new js query that does something like this:

form1.data.listView1.forEach(x => myQuery.trigger({additionalScope:{inputData:x.numberInput1}}) );

So you could trigger a resource query (myQuery) passing in the line item (and whatever other data you need from the form) and run it multiple times in a forEach loop.

Hope that logic makes sense - might be easier ways for you to do it depending on how you're doing the "add item" logic and how your resource query works.

Hi @dcartlidge, thanks for your suggestion!

That's successfully able to fire the query for each list item - though I'm having a hard time figuring out how pass the variables of each item through to the query. I'm assuming additionalScope is the way to do it, but I haven't been to get it to work yet.

invoiceForm.data.listView1.forEach(x => POST_invoiceItems.trigger({additionalScope:{price:x.stripe_product_id}}) )

Screenshot below shows the two variables I'm needing the values of in the query. Is there a way that I can access the values of the above query to specify them below?

You should pass the quantity togeter with price in additonalScope

invoiceForm.data.listView1.forEach(x => POST_invoiceItems.trigger({additionalScope:{price:x.stripe_product_id, quantity:x.***}}) )

Then

1 Like

This worked perfectly. Thanks so much for your help @AnsonHwang!