How to apply a condition of a list of numbers

I have this local variable

local!variable:
{2017,2018,2019,2020}

local!variable2:
a!forEach(
   items: local!variable,
   expression: if(fv!item<2018,"PRE-YEAR",fv!item)
 ),

I wanted a result like:

{"PRE-YEAR",2018,2019,2020}

Error:

Please help me 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Hello friend, 

    You are very close to your solution! 

    the error you are receiving is due to the comparison operand. You should just be able to do: if( to integer(fv!item) < 2018, "pre", fv!item)

    Furthermore, based on your output, it seems that you are doing this in an expression rule, so you'll have to return the value on it's own or as the name of the variable, please see below the code snippet: 

    -- Start

    local!variable: {2017, 2018, 2019, 2020}

    local!variable2: a!forEach(
        items: local!variable,
        expression: if( tointeger(fv!item) < 2018, "PRE-YEAR", fv!item)
    ),

    /*return */ 

    local!variable2

    -- End

    If this is the value you need to return, you can go without the local variable 2 and just explicitly do the a!forEach at the end of the rule, but if it's not, that should resolve your issue! Best wishes. 

Reply
  • 0
    Certified Lead Developer

    Hello friend, 

    You are very close to your solution! 

    the error you are receiving is due to the comparison operand. You should just be able to do: if( to integer(fv!item) < 2018, "pre", fv!item)

    Furthermore, based on your output, it seems that you are doing this in an expression rule, so you'll have to return the value on it's own or as the name of the variable, please see below the code snippet: 

    -- Start

    local!variable: {2017, 2018, 2019, 2020}

    local!variable2: a!forEach(
        items: local!variable,
        expression: if( tointeger(fv!item) < 2018, "PRE-YEAR", fv!item)
    ),

    /*return */ 

    local!variable2

    -- End

    If this is the value you need to return, you can go without the local variable 2 and just explicitly do the a!forEach at the end of the rule, but if it's not, that should resolve your issue! Best wishes. 

Children
No Data