Assign Multiple Years to Variable

Is there a way to assign multiple years to a variable and have that change with each new year? Right now, we have a variable called Years that holds the following data:

{“2020”, “2019”, “2018”, “2017”, “2016”}

Is there a way to have UiPath automatically populate each year from 2016 to current? Thanks in advance!


You can hold this data with List object.

Then you need to create a loop for getting the years from 2016, and add them to collection(List object) like below.

Erkan Ceylan

1 Like

have a look here as it can be done within an oneliner

Enumerable.Range(2016, 2020-2015).Reverse().Select(Function (x) x.toString).ToList

1 Like

Just one quick thing to add to ppr’s answer: The upper range is current year, so instead of hardcoding 2020 you can just use today.year instead


So I decided to go with ppr’s and Dave’s responses with the following:

Years = Enumerable.Range(2017, today.year+1-2017).Reverse().Select(Function (x) x.toString).ToList

I had to add the +1 because today.year was pulling 2019 for some reason. All of our computers are set to the current date. I found the +1 in another forum post.

Side note: Using this method required the Type Into activity. Neither the Set Text nor the Select Item activities worked.

Thanks for all the assistance! :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.