Update the sort ids if i am adding row in between existing rows .

Grid rows are shown on the based of sort id ,  I have implemented add button  in the grid just to add the new rows in between the existing rows, i have to update sort IDs if i am adding one or more than one row in between existing rows.

For an Example if  1,2,3,4 sort id's are already present and i am adding new row in 2nd index then existing 2 row id should change to 3 and remaining should increment . Where sort id is not primary key But the question id is .

a!imageField(
label: "Add " & ri!index,
images: a!documentImage(
document: a!iconIndicator("ADD"),
altText: "Add Question",
caption: "Add Question Here",
link:
a!dynamicLink(
label: "Add Question",
value: 'type!{urn:com:appian:types:Exit}Exit_Question'(

entityTypeId:"",
activeFlag: true,
sortId:ri!questions[ri!index].sortId+1,
contentAreaId: ri!contentAreaId,
createdBy: loggedInUser(),
createdDt: now(),
modifiedBy: loggedInUser(),
modifiedDt: now(),
questionIsRestricted: true
),
saveInto: {

a!save(
ri!questions,
insert(
ri!questions,
save!value,
ri!index+1
)
),

}

),

)
)

Above code just change the sort id of ne row but doesn't update the existing ones.

  Discussion posts and replies are publicly visible