Referencing the index of forEach loop

Certified Lead Developer

Hi,

I have nested forEach loop, Can we reference the index of parent forEach(first ForEach) loop inside the child loop(Second forEach)?

My use case is, I have a text box and an editable grid, both need to be looped for 5 times.so I have taken the nested for Each. Now when I removed the data from the editable grid, I am facing an issue like the data is removing from other local variable.

a!imageField(
label: "delete" & fv!index,
images: a!documentImage(
document: a!iconIndicator(
"REMOVE"
),
caption: fv!index,
altText: "Remove Mitigant",
link: a!dynamicLink(
value: fv!index,
saveInto: {
a!save(
choose(
fv!index,
local!data1,
local!data2,
local!data3,
local!data4,
local!data5
),
remove(
choose(
fv!index,
local!data1,
local!data2,
local!data3,
local!data4,
local!data5
),
save!value
)
)
}
)
),
size: "ICON"
)

This is the code for remove functionality.

Let me know if any other inputs required

  Discussion posts and replies are publicly visible

Parents
  • In the outer a!forEach, use a with() as the first function in the expression, and define a local that is the value of the index for the outer loop. The example below does something similar but with fv!item:

    load(
    local!letters: {"a","b","c"},
    local!numbers: {100,200,300},
    a!forEach(
    items: local!letters,
    expression: with(
    local!letter: fv!item,
    a!forEach(
    items: local!numbers,
    expression: concat(
    local!letter,
    "-",
    fv!item
    )
    )
    )
    )
    )
Reply
  • In the outer a!forEach, use a with() as the first function in the expression, and define a local that is the value of the index for the outer loop. The example below does something similar but with fv!item:

    load(
    local!letters: {"a","b","c"},
    local!numbers: {100,200,300},
    a!forEach(
    items: local!letters,
    expression: with(
    local!letter: fv!item,
    a!forEach(
    items: local!numbers,
    expression: concat(
    local!letter,
    "-",
    fv!item
    )
    )
    )
    )
    )
Children