How to bind the years dynamically to dropdown

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.

1 Like

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.

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.

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

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)
1 Like

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).

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

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.

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

Thanks.

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