# How to bind the years dynamically to dropdown

**URL:** <https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [June 20, 2022, 2:28pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953 "2022-06-20T14:28:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anita.Shinde](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@Anita.Shinde](https://forum.inductiveautomation.com/u/Anita.Shinde)\
**Post date:** [June 20, 2022, 2:28pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953/1 "2022-06-20T14:28:17Z")

</div>

Hi Team,

I want to bind year list in dropdown dynamically.  
years should be like 10 years minus from current year and 10 years plus from current year.  
e.g, I want years from 2012 to 2032(For now it is done hardcoded, I want to do it dynamic)  
I am using vision dropdown.  
Can anyone suggest How I can achieve this in ignition?  
Thanks.

---

<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 20, 2022, 2:42pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953/2 "2022-06-20T14:42:04Z")

</div>

If you are good with SQL you can look up how to list years like that and bind the data property to a SQL Query Binding or Named Query binding with your SQL.

Alternatively, you can write a script that makes a dataset using `system.dataset.toDataSet()`, leverage the `system.date.*` functions to make your list, and bind your data property with an expression binding that calls `runScript` and calls the function you wrote that returns the dataset of years.

---

<div class="post-metadata">

**Author:** ![Anita.Shinde](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@Anita.Shinde](https://forum.inductiveautomation.com/u/Anita.Shinde)\
**Post date:** [June 20, 2022, 2:46pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953/3 "2022-06-20T14:46:21Z")

</div>

Yeah, I am good in SQL, we can get list using CTE statement but we cant write CTE statement in Ignition vision.  
Will think on dataset.

Thank you.

---

<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 20, 2022, 3:20pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953/4 "2022-06-20T15:20:43Z")

</div>

Something like this. Columns may need switched around to work with Dropdown properly.

```auto
thisYear = system.date.getYear(system.date.now())

years = [[year] for year in range(thisYear - 10,thisYear + 11) if year != thisYear]

dataSet = system.dataset.toDataSet(['Year'],years)

```

---

<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:** [June 20, 2022, 4:28pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953/5 "2022-06-20T16:28:28Z")

</div>

Ignition can have CTEs in named queries, which you should be using for all Vision UI bindings. But generating via `runScript()` will be the most performant (no gateway round trip).

---

<div class="post-metadata">

**Author:** ![Anita.Shinde](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@Anita.Shinde](https://forum.inductiveautomation.com/u/Anita.Shinde)\
**Post date:** [June 20, 2022, 5:46pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953/6 "2022-06-20T17:46:09Z")

</div>

Where I can write above code in vision 7.3 version.  
I didnt see Script library there.

---

<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 20, 2022, 6:12pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953/7 "2022-06-20T18:12:25Z")

</div>

> [@Anita.Shinde](#):
>
> vision 7.3

Yikes! I hope you're working towards an upgrade as 7.9 is EOL in 1.5 weeks.

I don't know if the code I provided will work in 7.3 because I am not sure if `system.dataset.toDataSet()` was available.

---

<div class="post-metadata">

**Author:** ![Anita.Shinde](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@Anita.Shinde](https://forum.inductiveautomation.com/u/Anita.Shinde)\
**Post date:** [June 20, 2022, 6:14pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953/8 "2022-06-20T18:14:47Z")

</div>

yes, I am also not familiar with 7.3 version, so facing challenges.  
Can anyone suggest, how to do in 7.3 version?

Thanks.

---

<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:** [June 20, 2022, 6:46pm UTC](https://forum.inductiveautomation.com/t/how-to-bind-the-years-dynamically-to-dropdown/60953/9 "2022-06-20T18:46:13Z")

</div>

The manuals for that are not even online for us to use. You need to study the manuals that are installed with v7.3.
