# Delay query binding execution until all parameters have updated?

**URL:** <https://forum.inductiveautomation.com/t/delay-query-binding-execution-until-all-parameters-have-updated/93145>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [July 12, 2024, 2:18pm UTC](https://forum.inductiveautomation.com/t/delay-query-binding-execution-until-all-parameters-have-updated/93145 "2024-07-12T14:18:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [July 12, 2024, 2:18pm UTC](https://forum.inductiveautomation.com/t/delay-query-binding-execution-until-all-parameters-have-updated/93145/1 "2024-07-12T14:18:27Z")

</div>

I have a table populated from a query binding. Two of the parameters being passed to the query are pulled from properties that are generated from their own bindings. One of those properties' binding is dependent on the value of the other one. It appears that a change in the value of any of the query's parameters will cause it to re-evaluate, which makes sense. But due to the one value being dependent on the other, this means that a change in the first causes the query to execute, and then it gets executed _again_ as soon as the second value changes. So how would one go about making sure the query doesn't execute until that second property has updated based on the change in the first?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 12, 2024, 2:26pm UTC](https://forum.inductiveautomation.com/t/delay-query-binding-execution-until-all-parameters-have-updated/93145/2 "2024-07-12T14:26:25Z")

</div>

Use an expression structure binding (or my `asMap()` and `transform()` expression functions) to generate those values in a single binding. Then point the NQ binding at that object's inner elements.

With my Integration Toolkit, do something like this:

```python
transform(
	....., // First expression
	asMap(
		'firstKey', value(),
		'secondKey', ..... // Second expression, with value() where needed for the first result
	)
)

```

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [July 12, 2024, 4:14pm UTC](https://forum.inductiveautomation.com/t/delay-query-binding-execution-until-all-parameters-have-updated/93145/3 "2024-07-12T16:14:02Z")

</div>

I put the two values into a single object that is updated by an expression structure binding (with "Wait On All" checked). I put a debug print in a change script on that object to verify that it is only changing once. Yet, the query is executing twice...

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [July 12, 2024, 10:29pm UTC](https://forum.inductiveautomation.com/t/delay-query-binding-execution-until-all-parameters-have-updated/93145/4 "2024-07-12T22:29:16Z")

</div>

[TestQueryBinding\_2024-07-12\_1721.zip](https://forum.inductiveautomation.com/uploads/short-url/q41SaOUds8iszN8kZ3fsV4AJkXo.zip) (32.6 KB)  
I created this very simple project to demonstrate the problem. Toggling a checkbox causes an Expression Structure binding to update two values in a single object, which are passed as parameters to a Query binding. Debug prints show the change in the object followed by two invocations of a script transform applied to the query:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/0/a0110c2cf6fe0006e413dec6766b8235db955ef2.png)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 12, 2024, 10:32pm UTC](https://forum.inductiveautomation.com/t/delay-query-binding-execution-until-all-parameters-have-updated/93145/5 "2024-07-12T22:32:03Z")

</div>

Hmm. Not what I expected. Might not be able to use a query binding for your case.

Consider using a property binding to the outer object, and running the NQ from a script transform attached to that. The script would pass the outer object as the NQ's parameters dictionary, if you take care to match up the expected keys.

---

<div class="post-metadata">

**Author:** ![Ryan\_Deardorff](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan_deardorff/32/63815_2.png) [@Ryan\_Deardorff](https://forum.inductiveautomation.com/u/Ryan_Deardorff)\
**Post date:** [July 15, 2024, 4:42pm UTC](https://forum.inductiveautomation.com/t/delay-query-binding-execution-until-all-parameters-have-updated/93145/6 "2024-07-15T16:42:55Z")

</div>

I tried that, and it seems to work...until it doesn't. Sometimes the expression structure gets executed twice...  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/0/90fecaf13770375dec0015b7d2bfde8cb604ca61.png)  
Seems like a bug...

(This is all on 8.1.36)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 15, 2024, 5:08pm UTC](https://forum.inductiveautomation.com/t/delay-query-binding-execution-until-all-parameters-have-updated/93145/7 "2024-07-15T17:08:50Z")

</div>

I will admit to never using expression structure bindings, as my `asMap()` can create such arbitrary objects, and can use dynamic keys. Consider trying my Integration Toolkit's expression functions to build your object, before handing it to your script transform.
