Editable Grid Issue : Not able to remove and update data in database

When I try to remove grid row that time shows this error :  "An error occurred while executing a save: Expression evaluation error at function 'remove' [line 103]: Invalid index (3) for list: valid range is 1...1"

When I try to Update grid row that time shows this error :  "An error occurred while executing a save: Expression evaluation error: The save target must be a local variable that does not refresh on every evaluation or on an interval, a process variable, or a node input (or a rule input passed one of those three), but instead was: [startIndex=1, batchSize=-1, sort=[field=Name, ascending=true], totalCount=7, data=[......], identifiers=10; 9; 11; 1; 12; 8; 39]" 

Code: 

load(
ri!Customer: rule!CustomerInfo_ExpRule(),
with(
a!formLayout(
label: "Add,Update, or Remove Customer Data",
contents: {
a!gridLayout(
totalCount: count(ri!Customer),
headerCells: {
a!gridLayoutHeaderCell(label: "Name" ),
a!gridLayoutHeaderCell(label: "Address" ),
a!gridLayoutHeaderCell(label: "OrgName" ),
a!gridLayoutHeaderCell(label: "Salary" ),
a!gridLayoutHeaderCell(label: "ContactNo" ),
a!gridLayoutHeaderCell(label: "Emaild"),
a!gridLayoutHeaderCell(label: "Location"),
a!gridLayoutHeaderCell(label: "" )
},

columnConfigs: {
a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:2 ),
a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:4 ),
a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
a!gridLayoutColumnConfig(width: "ICON")
},
rows: a!forEach(
items: rule!CustomerInfo_ExpRule(),
expression: a!gridRowLayout(
id: fv!index,
contents: {

a!textField(

label: "Name" & fv!index,
value: fv!item.Name,
saveInto: fv!item.Name,
required: true
),

a!textField(
label: "Address" & fv!index,
value: fv!item.Address,
saveInto: fv!item.Address,
required:true
),

a!textField(
label: "OrgName" & fv!index,
value: fv!item.OrgName,
saveInto: fv!item.OrgName,
required:true
),
a!floatingPointField(
label: "Salary" & fv!index,
value: fv!item.Salary,
saveInto: fv!item.Salary,
required:true
),
a!integerField(
label: "ContactNo" & fv!index,
value: fv!item.ContactNo,
saveInto: fv!item.ContactNo
),
a!textField(
label: "EmailID" & fv!index,
value: fv!item.Emaild,
saveInto: fv!item.Emaild,
required:true
),

a!textField(
label: "Location" & fv!index,
value: fv!item.Location,
saveInto: fv!item.Location,
required:true
),
a!imageField(
label: "delete " & fv!index,
images: a!documentImage(
document: a!iconIndicator("REMOVE"),
altText: "Remove Customer",
caption: "Remove " & fv!item.Name,
link: a!dynamicLink(
value: fv!index,
saveInto: {
a!save(ri!Customer, remove(ri!Customer, save!value)),
a!save(ri!DeletedCustomer, append(ri!DeletedCustomer, fv!item)),
a!deleteFromDataStoreEntities(
a!entityDataIdentifiers(
entity: cons!DSE_CustomerInfo,
identifiers: ri!DeletedCustomer
)
)
}
)
),
size: "ICON"
)
}
)
)
,
addRowlink: a!dynamicLink(
label: "Add Employee",

value: 'type!{urn:com:appian:types}CustomerInfo'(),
saveInto: {
a!save(ri!Customer, append(ri!Customer,save!value))
}
)
)
},
buttons: a!buttonLayout(
primaryButtons: a!buttonWidgetSubmit(
label: "Submit",
saveInto:{ a!writeToDataStoreEntity(
dataStoreEntity: cons!DSE_CustomerInfo,
valueToStore: ri!Customer
)
}
)
)
)
)
)

Thanks,

Kunal

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    You are creating a local variable, within load(), called ri!customer (which is not a naming convention that should typically be used with local variables), based on rule!CustomerInfo_ExpRule().  But then when you generate your grid rows, you're apparently also basing that directly on rule!CustomerInfo_ExpRule().  And then finally, in your remove() statement, you're attempting to remove directly from ri!customer.  This is fairly confusing, TBH - I would be surprised if there weren't several issues with this at the moment.  I can see what you're trying to do in a big picture sense, but I have no idea how you're expecting it to work.

    Also: when posting large code snippets like this, you should use "Insert --> Insert Code" functionality within the text editor here, and paste the code into the resultant code boxes, making sure that proper indentation is preserved.  That honestly makes it a lot easier to read than 3 screens full of unindented unformatted post text.

  • Hi Mike,

    Now I replace the local!customer with ri!Customer :

    load(
    ri!Customer: rule!CustomerInfo_ExpRule()

    Please check below snippet for remove the row : "An error occurred while executing a save: Expression evaluation error at function 'remove' [line 103]: Invalid index (3) for list: valid range is 1...1"

    a!imageField(                                
    label: "delete" & fv!index,
    images: a!documentImage(
    document: a!iconIndicator("REMOVE"),
    altText: "Remove Customer",
    caption: "Remove " & fv!item.Name,
    link: a!dynamicLink(
    value: fv!index,
    saveInto: {a!save(ri!Customer, remove(ri!Customer, save!value)),
    a!save(ri!DeletedCustomer,remove(ri!DeletedCustomer,fv!item.Id)),
    a!deleteFromDataStoreEntities(
    a!entityDataIdentifiers(
    entity: cons!DSE_CustomerInfo,
    identifiers: ri!DeletedCustomer
    )
    )
    }
    )
    ),
    size: "ICON"
    )

    Thanks,

    Kunal

  • 0
    Certified Lead Developer
    in reply to kunald0002

    I think your local variable should be named in the standard convention of local!customer instead of ri!customer unless you have an unusually important reason for doing it that way.

    Aside from that: what is the output of your rule rule!CustomerInfo_ExpRule()?  If it's not actually producing an array of CDT, then you could be getting the attached error, but it's hard to tell either way without seeing a sample of its output.

  • rule!CustomerInfo_ExpRule() : its fetch the data from database & populate that data on the grid

    below query i write in this exp rule :

    a!queryEntity(
    entity: cons!DSE_CustomerInfo,
    query: a!query(
    pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: -1

    ),
    selection:a!querySelection(
    columns: {
    a!queryColumn( field: "Name"),
    a!queryColumn( field: "Address"),
    a!queryColumn( field: "OrgName"),
    a!queryColumn( field: "Salary"),
    a!queryColumn( field: "ContactNo"),
    a!queryColumn( field: "Emaild"),
    a!queryColumn( field: "Location")

    }
    )

    )

    )