Skip to main content
August 30, 2021
Question

How to update the ids in grid of specific rows?

  • August 30, 2021
  • 1 reply
  • 0 views

in the editable grid i am having i am displaying Questions and some other values on the basis of Sort id , Where sort ID is not primary key , i have also provided  button to add new rows in between existing rows . below code works fine and increment the values automatically if new row gets added in between 

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:Test}Test_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}
)
)
),
a!save(local!test,true())
,


}
),

)
)

But this code fails beacuse there is a  dropdown field  in grid named entity type having value ("Null", Provisonal ,"Production")  when we are adding new row ,increment should happens only for the rows which are having enity type id null . if other values like "Provisional" and "production" for them sort id should not change or increment. 

(This scenerio is not happening, i know there will be duplicates in ID for null entity type and provisional and production)

1 reply

gayathris111098
August 31, 2021

Can you share UI and explain more?

But for your question how to update specific rows you can write condition like below and call it in the saveInto of any fields

a!forEach(
  items: ri!Questions,
  expression: if(
    and(fv!item.active, tointeger(fv!item.id) > 1),
    a!update(fv!item, "id", 1),
    fv!item
  )
)