updatearray with foreach

How do i retain updated array's positional values during each iteration of foreach ?

Example :

Trying to update second and third index to 1 depending on the rule input

ri!selectedMonths -> {2,3}

desired result -> {0,1,1,0,0,0,0,0,0,0,0,0}

 

load(

local!allmonths:index({},enumerate(12),0),
 

a!forEach(
  items: ri!selectedMonths,
  expression:
  fn!updatearray(local!allmonths,fv!item,1)

)
)

 

The result of the rule repeats itself for every execution without retaining the value from previous execution.

Second execution updates second index position , third execution updates third position but reevaluates the array without retaining value from second execution.

  Discussion posts and replies are publicly visible

Parents
  • Hi, I didn't understand why u r using a!forEach() function. If you req to update specific index in an array, u can simply use the updatearray() as below

    load(
    local!months:index({},enumerate(12),0),
    local!array:fn!updatearray(local!months,ri!selectedMonths,1),
    local!array
    )
    If this is not what you required, then plz explain in more detail what u r trying to achieve.
Reply
  • Hi, I didn't understand why u r using a!forEach() function. If you req to update specific index in an array, u can simply use the updatearray() as below

    load(
    local!months:index({},enumerate(12),0),
    local!array:fn!updatearray(local!months,ri!selectedMonths,1),
    local!array
    )
    If this is not what you required, then plz explain in more detail what u r trying to achieve.
Children
No Data