# Is it possible to populate different checkboxes from a query?

**URL:** <https://forum.inductiveautomation.com/t/is-it-possible-to-populate-different-checkboxes-from-a-query/95946>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 13, 2024, 12:27pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-populate-different-checkboxes-from-a-query/95946 "2024-09-13T12:27:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [September 13, 2024, 12:27pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-populate-different-checkboxes-from-a-query/95946/1 "2024-09-13T12:27:24Z")

</div>

Hello!

To filter a table a need multiple filters array, I would need checkboxes so visually I can tell wich one is selected or not. It´s possible to populate different checkboxes from a single query?

For example if I got a query with [ACC,PRF,PRL,PRR,Z1,Z2...]

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/1/1176724cb1f815dcf75713e1bb31a8e73cbee9f9.png)

---

<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:** [September 13, 2024, 12:32pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-populate-different-checkboxes-from-a-query/95946/2 "2024-09-13T12:32:50Z")

</div>

Do you have a single query that can get all your data points? Something like

```python
SELECT
    ACC,
    PRF,
    PRL,
    #rest of columns
FROM someTable

```

?

If so,I would put that in a custom proprety somewhere, or a session prop if this is used all over your project, and then you can use `try({path.to.dataset},[0, 'ACC'], False)` where 0 is the row number (Assuming you can get this all in one row), 'ACC' is the column name, and False represents a fallback value you don't get anything, to get the value out of that dataset. Bind it to the selected prop.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [September 13, 2024, 12:39pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-populate-different-checkboxes-from-a-query/95946/3 "2024-09-13T12:39:01Z")

</div>

The query is :

```python
SELECT DISTINCT
CASE 
WHEN A.COMPANYLEVEL=5 THEN SUBSTR(WO.ASSET,11)
WHEN A.COMPANYLEVEL > 5 THEN SUBSTR((SELECT APA.PARENTASSET FROM ASSETPARENTASSET APA INNER JOIN ASSET B ON 
APA.COMPANY=B.COMPANY AND APA.PARENTASSET=B.ASSET WHERE APA.COMPANY=WO.COMPANY AND APA.ASSET=WO.ASSET AND 
A.COMPANYLEVEL=5),11)
ELSE N'SD' END AS FAMILIA,0 AS INCLUDED

FROM WORKORDER WO INNER JOIN ASSET A ON WO.COMPANY=A.COMPANY AND WO.ASSET=A.ASSET
WHERE WO.COMPANY='TIENDAS'
ORDER BY FAMILIA

```

I learnt this from Transistor.

with the result [ACC,PRF,PRL,PRR,Z1,Z2...]

then will need to filter a table based on the correspondent checkboxes

I will do a custom property with a expression structure  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/b/6b0166f40e60ce579332fd9a751a9cc6c2249b5a.png)

and the script transform like:

```python

    selected_work_types = []

    # Check each work type checkbox and append corresponding value if selected
    if value['listWorkType_ACC']:
        selected_work_types.append('ACC')
    if value['listWorkType_PRF']:
        selected_work_types.append('PRF')
    if value['listWorkType_PRL']:
        selected_work_types.append('PRL')
    if value['listWorkType_PRR']:
        selected_work_types.append('PRR')
    if value['listWorkType_Z1']:
        selected_work_types.append('Z1')
    if value['listWorkType_Z2']:
        selected_work_types.append('Z2')
    if value['listWorkType_Z3']:
        selected_work_types.append('Z3')
    if value['listWorkType_Z4']:
        selected_work_types.append('Z4')
    if value['listWorkType_Z5']:
        selected_work_types.append('Z5')

    # Return a comma-separated string of selected work types, or None if none are selected
    return ','.join(selected_work_types) if selected_work_types else None

```

the problem is that i would like to get the checkboxes values from the query and not fixed

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [September 13, 2024, 12:42pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-populate-different-checkboxes-from-a-query/95946/4 "2024-09-13T12:42:23Z")

</div>

If you have the data in a dataset somewhere you can just bind the checkbox with an expression to the selected record and field

`{../Table.props.selection.data[0].ACC}`

---

<div class="post-metadata">

**Author:** ![Alejandro\_Alaco](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alejandro_alaco/32/59849_2.png) [@Alejandro\_Alaco](https://forum.inductiveautomation.com/u/Alejandro_Alaco)\
**Post date:** [September 13, 2024, 12:44pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-populate-different-checkboxes-from-a-query/95946/5 "2024-09-13T12:44:36Z")

</div>

Ok, thank you all, will try, coming back if I have some issue!

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [September 13, 2024, 1:24pm UTC](https://forum.inductiveautomation.com/t/is-it-possible-to-populate-different-checkboxes-from-a-query/95946/6 "2024-09-13T13:24:57Z")

</div>

> [@Alejandro\_Alaco](#):
>
> ```python
> WHEN A.COMPANYLEVEL > 5 THEN SUBSTR((SELECT APA.PARENTASSET FROM ASSETPARENTASSET APA INNER JOIN ASSET B ON 
> APA.COMPANY=B.COMPANY AND APA.PARENTASSET=B.ASSET WHERE APA.COMPANY=WO.COMPANY AND APA.ASSET=WO.ASSET AND 
> A.COMPANYLEVEL=5),11)
> 
> ```

This sub query here will make your query slow. It also likely depends on it returning only a single value. I would see if you can merge this into the main query instead, otherwise that query will be run for every single row that's returned. I would also format the whole query to be more readible for future you and future other people
