Skip to main content
March 30, 2023
Solved

A simple loop

  • March 30, 2023
  • 5 replies
  • 0 views

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.

Best answer by alexandru.boerescu

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

5 replies

alexandru.boerescu
March 30, 2023

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

March 30, 2023

a!localVariables(
  local!years: 15,
  enumerate(local!years + 2) + year(today()) - local!years
)

stefanhelzle0001
Brainy
March 30, 2023

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/

March 30, 2023

Hey, you multiplied it by 5 there [emoticon:4b473fb4671244b2a5887318abe9e44a]

stefanhelzle0001
Brainy
March 30, 2023

LOL, That's why I use Appian. It is just better than me in math ;-)