I want to do something like this:
CONST MIN_YEAR = 15
int[] yearOptions
for int i = year(date)-MIN_YEAR to year(date)+1 {
yearOptions.push(i)
}
How can I do this in Appian?I suspect this need to be an expression rule and the number 15 may change while I'm working on the interface.
Discussion posts and replies are publicly visible
You could use a script like the one below. Save the output in another variable and change the format as you see fit.
a!localVariables( local!years: 15, { a!forEach( items: enumerate(local!years+2), expression: year(today()) - local!years + fv!item ) } )
a!localVariables( local!years: 15, enumerate(local!years + 2) + year(today()) - local!years )
The Appian expression language follows a function paradigm. Variables are immutable. But just like Python, Appian can do some nifty magic on list types.
Simple example: {1,2,3,4,5} * 5 = {3,6,9,12,15} {5, 10, 15, 20, 25}
Sanchit provided another example. Check out my blog for how to implement more complex algorithms. https://appian.rocks/2022/08/29/complex-algorithms-in-appian/
Hey, you multiplied it by 5 there
LOL, That's why I use Appian. It is just better than me in math ;-)