Skip to main content
February 23, 2024
Question

update a value at the current index then increment at other indexes

  • February 23, 2024
  • 4 replies
  • 0 views

Hi, In foreach loop I am fetching some value. So the requirement is at current index of foreach loop I am updating some default value and then at the proceeding indexes i want to increment by one in the default value. Here is how I am doing it.

a!forEach(
items: local!rawData_at,
expression:
if(fv!index = 1,

a!update(fv!item,"KeyTaskModel",ri!KeyTaskModel_StartingOrder_int),
a!update(fv!item,"KeyTaskModel",fv!index+1)

))

What it is doing is i have saved the value from rule input ri!KeyTaskModel_StartingOrder_int at the first index but the subsequent indexes is adding value to the index value not the rule input value. How can I achieve that? attaching the output below.

4 replies

stefanhelzle0001
February 23, 2024

What exactly do you mean with this?

but the subsequent indexes is adding value to the index value not the rule input value

In an expression, you cannot add anything to a rule input. The only thing an expression can do, is to take some input values, and generate an output.

davidj137213
February 23, 2024

Could you post here the expected output please?

harshitb6843
February 23, 2024

Try this 

a!forEach(
  items: local!rawData_at,
  expression: a!update(
    fv!item,
    "KeyTaskModel",
    (fv!index - 1) + fv!KeyTaskModel_StartingOrder_int
  )
)

February 23, 2024

it worked thanks.