Hi
You need to pass your current index to get updated index value. Use this sample code to updated your logic.
a!localVariables(
/*Consider this is your CDT*/
local!employees: {
a!map( firstName: "John" , lastName: "Smith" ),
a!map( firstName: "John" , lastName: "Smith" ),
a!map( firstName: "John" , lastName: "Smith" )
},
a!formLayout(
label: "Grid",
contents: {
a!gridLayout(
totalCount: count(local!employees),
headerCells: {
a!gridLayoutHeaderCell(label: "ID" ),
a!gridLayoutHeaderCell(label: "First Name" ),
a!gridLayoutHeaderCell(label: "Last Name" ),
a!gridLayoutHeaderCell(label: "" )
},
/* Only needed when some columns need to be narrow */
columnConfigs: {
a!gridLayoutColumnConfig(width: "ICON"),
a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
a!gridLayoutColumnConfig(width: "ICON")
},
rows: a!forEach(
items: local!employees,
expression: a!gridRowLayout(
contents: {
a!textField(
label: "id" & fv!index,
value: fv!index,
readOnly: true
),
a!textField(
label: "first name " & fv!index,
value: fv!item.firstName,
saveInto: fv!item.firstName,
required: true
),
a!textField(
label: "last name " & fv!index,
value: fv!item.lastName,
saveInto: fv!item.lastName,
required:true
),
a!richTextDisplayField(
value: a!richTextIcon(
icon: "close",
altText: "delete " & fv!index,
caption: "Remove " & fv!item.firstName & " " & fv!item.lastName,
link: a!dynamicLink(
value: fv!index,
saveInto: {
a!save(local!employees, remove(local!employees, save!value))
}
),
linkStyle: "STANDALONE",
color: "NEGATIVE"
)
)
},
id: fv!index
)
),
addRowlink: a!dynamicLink(
label: "Add Employee",
value: {
a!map(
firstName: null,
lastName: null
)
},
saveInto: {
a!save(local!employees, append(local!employees, save!value))
}
),
rowHeader: 1
)
},
buttons: a!buttonLayout(
primaryButtons: a!buttonWidget(
label: "Submit",
submit: true
)
)
)
)