# Query Binding to a custom parameter in a view

**URL:** <https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048>\
**Category:** Ignition\
**Created:** [June 22, 2022, 8:45am UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048 "2022-06-22T08:45:27Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [June 22, 2022, 8:45am UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/1 "2022-06-22T08:45:27Z")

</div>

I have defined a custom property in a view (say taskdata) which I bind to an SQL Query returning a row from a database in a say [0x8] dataset for single row of data. Now I want to bind text property of 8 different labels on the view to the individual cells of the row dataset. How to do that?

The property binding shows that it is a dataset correctly, as shown in the image below, but how to access its individual cells while binding to label's text property? (I tried putting suffix [0,1] in obviously vain!)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/0/30ce63a93897d26b0a79c790d0e23eb0fc1e8fe9.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 22, 2022, 8:59am UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/2 "2022-06-22T08:59:07Z")

</div>

If your dataset is `[0x8]` that means it’s empty :X

When you get your query working, you can access a cell from a row quite easily with an expression binding: `{view.custom.dataset}[x]` where `x` is the 0-based index of the row.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [June 22, 2022, 9:35am UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/3 "2022-06-22T09:35:44Z")

</div>

Not really! Here is the binding without the index, which shows the result as a data set [0x8] However assigning index [1] to it gives binding error! - see second screen shot. I even tried [0,1] but same error

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/6/c60b62c95a2d9e0205265b9ba816bcadd53d6419.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/e/6ec22ea793ef7d323338a59c1238aa73da04929e.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 22, 2022, 11:25am UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/4 "2022-06-22T11:25:24Z")

</div>

Yes, because your dataset is empty.

> [@pascal.fragnoud](#):
>
> **When you get your query working** , you can access a cell from a row quite easily with an expression binding: `{view.custom.dataset}[x]` where `x` is the 0-based index of the row.

edit:  
If you need to handle empty datasets:

```auto
if(len({view.custom.dataset}),
	{view.custom.dataset}[x],
	null
)

```

This will return the cell at index `x` if the dataset is not empty, and `null` if it's empty.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [June 22, 2022, 4:47pm UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/5 "2022-06-22T16:47:03Z")

</div>

But when does the query get executed to initialize the custom property in the view? When the View is displayed or any other event?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 22, 2022, 6:36pm UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/6 "2022-06-22T18:36:16Z")

</div>

If it’s a query binding, it should execute periodically based on the query’s poll rate. I think.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [June 22, 2022, 6:57pm UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/7 "2022-06-22T18:57:40Z")

</div>

> [@pascal.fragnoud](#):
>
> it should execute periodically based on the query’s poll rate

The binding's poll rate.

In design it should run when you apply any changes, to that binding.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 22, 2022, 7:14pm UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/8 "2022-06-22T19:14:00Z")

</div>

Personally I’m a fan of doing it the pythonic way - try first, ask forgivness later. Also makes it so you don’t have to check the length.

`try({view.custom.dataset}[x],null)`

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 22, 2022, 7:43pm UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/9 "2022-06-22T19:43:46Z")

</div>

> [@prafull\_j](#):
>
> I have defined a custom property in a view (say taskdata) which I bind to an SQL Query returning a row from a database ...

In the designer go to the Property Editor and inspect `view.custom.taskdata`. I think you'll find that it is empty.

Fix your query so that some data shows up here and then your label bindings should work.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [June 23, 2022, 3:19am UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/13 "2022-06-23T03:19:15Z")

</div>

The table was empty though the headers are correctly filled. I found the problem; the query has an input field which comes from a parameter coming from the parent view of the view. Default value of this input field was left blank, so the query was returning null ! On giving an initial value it initializes the table and the binding to label text should work now! Thanks a lot all.

However the original question remains, when query return null, whats the best way to access the individual elements of the data set having null value!

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [June 23, 2022, 3:50am UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/14 "2022-06-23T03:50:50Z")

</div>

My first problem is solved as explained above. It definitely executes the query for the first time while binding. However not sure when does it update by default when execution rate is not defined in the binding window. My guess is by default it will execute only when the view is loaded, unless specified an execution rate in the window in which it will execute periodically as you mentioned. Which makes sense actually.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [June 23, 2022, 4:03am UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/15 "2022-06-23T04:03:20Z")

</div>

Yes works fine! Thanks!

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [June 23, 2022, 4:03am UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/16 "2022-06-23T04:03:43Z")

</div>

This also works fine! Thanks!

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [June 23, 2022, 7:41am UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/17 "2022-06-23T07:41:52Z")

</div>

Didn’t know this existed. I really should study expressions a bit more…

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 23, 2022, 12:09pm UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/18 "2022-06-23T12:09:48Z")

</div>

It’s a very nice and more succint technique I learned from @pturmel. I use it a lot for add/edit windows. For a text box for instance, I put a custom property I tend to call `initialValue` and bind that to `try({Root Container.initialData}[0, 'someColumn'], 'DEFAULT VALUE FOR CREATE')`. Then I would bind my text property to the `initialValue` property and now I have set up the text box for loading a record and provided what should be in the text box for a new record in a single expression.

---

<div class="post-metadata">

**Author:** ![PRAMANJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pramanj/32/66935_2.png) [@PRAMANJ](https://forum.inductiveautomation.com/u/PRAMANJ)\
**Post date:** [June 23, 2022, 1:46pm UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/19 "2022-06-23T13:46:16Z")

</div>

perhaps it may be computationally more efficient as well than checking the length of the dataset!

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 1, 2022, 5:27pm UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/20 "2022-08-01T17:27:01Z")

</div>

How do I just check the output of the a dataset for null?  
My label shows as` "[]"`

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 1, 2022, 5:29pm UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/21 "2022-08-01T17:29:12Z")

</div>

Check that the number of rows in greater than 0

```auto
if not ds.rowCount:
    #do work with dataset

```

or

```auto
if not ds.rowCount == 0:
    #do work with dataset

```

If you prefer, either will work.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [August 1, 2022, 5:42pm UTC](https://forum.inductiveautomation.com/t/query-binding-to-a-custom-parameter-in-a-view/61048/22 "2022-08-01T17:42:37Z")

</div>

I didn’t ask my question right. I set the output as scalar, then it told me the output was null from the query. However, your answer got me the solution.  
`if not value:`
