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
Hi,
We need to update the sort Ids of the other fields in the dictionary like below(this is just a simple method out of many):
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, a!forEach( items: ri!questions, expression: if( tointeger(fv!item.sortId) <= tointeger( index(ri!questions[ri!index], "sortId", null()) ), fv!item, updatedictionary( fv!item, { sortId: tointeger(fv!item.sortId) + 1 } ) ) ) ), a!save( ri!questions, insert(ri!questions, save!value, ri!index + 1) ) } ) ) )
Hope this helps!
Yea this is also fine , we can do like this ,just to update sort id by using function update disctionary
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:GID}GID_Question'( entityTypeId:"", activeFlag: true, 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 ) ), a!save( ri!questions, a!forEach( items: ri!questions, expression: updatedictionary( dictionary: fv!item, fieldsAndValues: { sortId: fv!index
} ) )) }