Editable Data Grid Error - Add/Remove rows from data grid whose data is from a query

Dear All,

I created an editable datagrid from sample code found from the SAIL Recipes and it fetches the data fine, and I am happy about that.

However, when I delete a row or add a row to my grid I get the following errors -

In Design Time, I get:
Could not display interface. Please check definition and inputs.
Interface Definition: Expression evaluation error: An error occurred while executing a save: Expression evaluation error at function 'remove' [line 309]: Invalid index (3) for list: valid range is 1...1


During Runtime, I get:
Error Evaluating UI Expression
Expression evaluation error in rule 'cshv_initiator_rework' at function a!forEach [line 207]: Error in a!forEach() expression during iteration 1: Expression evaluation error at function a!textField [line 213]: Invalid index: Cannot index property 'itemName' of type Text into type DataSubset

Here below is the SAIL code for my editable grid.  Can some find where the problem might lie?

Thanks

---

local!lineItemsPagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: 10
    ),
 
local!input: a!queryEntity(
  entity:cons!CSHV_LINE_ITEM_CDT,
  query:a!query(
 selection: a!querySelection(columns: {
   a!queryColumn(field: "itemName"),
   a!queryColumn(field: "amount"),
   a!queryColumn(field: "qty"),
   a!queryColumn(field: "total")
 }),
  filter: a!queryFilter(
 field: "cashAdvnaceId.id",
 operator: "=",
 value: ri!CashAdvanceRequestData.id
  ),
  PagingInfo: local!lineItemsPagingInfo
  )
),
 
  local!gridSelection: a!gridSelection(
  selected: {},
  pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: 10,
    sort: a!sortInfo(
      field: "timeStamp",
      ascending: false
    )
  )
),

a!gridLayout(
  totalCount: count(
 local!lineItemsPagingInfo
  ),
  headerCells: {
 a!gridLayoutHeaderCell(
   label: "Item"
 ),
 a!gridLayoutHeaderCell(
   label: "Amount",
   align: "RIGHT"
 ),
 a!gridLayoutHeaderCell(
   label: "Qty",
   align: "RIGHT"
 ),
 a!gridLayoutHeaderCell(
   label: "Total",
   align: "RIGHT"
 ),
 /* For the "Remove" column */
 a!gridLayoutHeaderCell(
   label: ""
 )
  },
  /* Only needed when some columns need to be narrow */
  columnConfigs: {
 a!gridLayoutColumnConfig(
   width: "DISTRIBUTE",
   weight: 7
 ),
 a!gridLayoutColumnConfig(
   width: "DISTRIBUTE",
   weight: 2
 ),
 a!gridLayoutColumnConfig(
   width: "DISTRIBUTE",
   weight: 1
 ),
 a!gridLayoutColumnConfig(
   width: "DISTRIBUTE",
   weight: 2
 ),
 a!gridLayoutColumnConfig(
   width: "ICON"
 )
  },
  rows: a!forEach(
 items: local!input,
 expression: a!gridRowLayout(
   id: fv!index,
   contents: {
  /* For the Item Name Column*/
  a!textField(
    /* Labels are not visible in grid cells but are necessary to meet accessibility requirements */
    label: "item " & fv!index,
    value: fv!item.itemName,
    saveInto: fv!item.itemName,
    required: true
  ),
  /* For the Amount Column*/
  a!floatingPointField(
    label: "Amount " & fv!index,
    labelPosition: "ADJACENT",
    value: fv!item.amount,
    saveInto: {
   fv!item.amount,
   if(
     rule!APN_isBlank(
    fv!item.qty
     ),
     "",
     a!save(
    fv!item.total,
    product(
      fv!item.amount,
      fv!item.qty
    )
     )
   )
    },
    refreshAfter: "UNFOCUS",
    validations: {},
    align: "RIGHT"
  ),
  /* For the Qty Column*/
  a!floatingPointField(
    label: "Qty " & fv!index,
    labelPosition: "ADJACENT",
    value: fv!item.qty,
    saveInto: {
   fv!item.qty,
   if(
     rule!APN_isBlank(
    fv!item.amount
     ),
     "",
     a!save(
    fv!item.total,
    product(
      fv!item.amount,
      fv!item.qty
    )
     )
   )
    },
    refreshAfter: "UNFOCUS",
    validations: {},
    align: "RIGHT"
  ),
  /* For the Total Column*/
  a!floatingPointField(
    label: "Total " & fv!index,
    labelPosition: "ADJACENT",
   
    value: if(
   or(
     rule!APN_isBlank(
    fv!item.amount
     ),
     rule!APN_isBlank(
    fv!item.qty
     )
   ),
   fv!item.total,
   product(
     fv!item.amount,
     fv!item.qty
   )
    ),
    saveInto: fv!item.total,
    refreshAfter: "UNFOCUS",
    validations: {},
    align: "RIGHT"
  ),
  /* For the Removal Column*/
  a!imageField(
    label: "delete " & fv!index,
    images: a!documentImage(
   document: a!iconIndicator(
     "REMOVE"
   ),
   altText: "Remove Line Item",
   caption: "Remove " & fv!item.item & " " & fv!item.lastName,
   link: a!dynamicLink(
     value: fv!index,
     saveInto: {
    a!save(
      local!input,
      remove(
     local!input,
     save!value
      )
    )
     }
   )
    ),
    size: "ICON"
  )
   }
 )
  ),
  addRowlink: a!dynamicLink(
 label: "Add a new line.",
 saveInto: {
   a!save(
  local!input,
  append(
    local!input,
    save!value
  )
   )
 }
  )
)

  Discussion posts and replies are publicly visible

  • The iteration is done using foreach() and the array used is a type daatsubset. This datasubset is mapped to a local parameter local!input. a!queryentity() would return a datasubset but while displaying you would need the data attribute of the datasubset so please try replacing the code of local!input as
    local!input: a!queryEntity(
    entity: cons!NSB_ENTITY_REQUESTS,
    query: a!query(
    selection: a!querySelection(columns: {
    a!queryColumn(field: "itemName"),
    a!queryColumn(field: "amount"),
    a!queryColumn(field: "qty"),
    a!queryColumn(field: "total")
    }),
    filter: a!queryFilter(
    field: "cashAdvnaceId.id",
    operator: "=",
    value: ri!CashAdvanceRequestData.id
    ),
    PagingInfo: local!lineItemsPagingInfo
    )
    ).data,
  • Hi

    Change -->rows: a!forEach(
    items: local!input.. to
    --> rows: a!forEach(
    items: local!input.data...
  • 0
    A Score Level 1
    in reply to prernas

    Thanks Prenars,

    Now, I can remove and add rows.  

    However, there is a new problem with the new blank rows added.  The Amount, Qty and Total columns are used for calculations and when the row is added, and I try to columns need to edit any of those columns, I get the error below:

    Could not display interface. Please check definition and inputs.
    Interface Definition: Expression evaluation error: An error occurred while executing a save: java.lang.IllegalArgumentException: Invalid index: Cannot index property 'amount' into type List of Null

    Is there a way around this?

    Thanks

  • 0
    A Score Level 1
    in reply to ankitab0001
    Thanks Ankita,

    I made the change to input.data but then the rows now show as blank rows (without any data in them). Secondly, now, I get the error below when I try to edit the Amount, Qty or Total columns. These three columns are used in calculations.

    Could not display interface. Please check definition and inputs.
    Interface Definition: Expression evaluation error: An error occurred while executing a save: java.lang.IllegalArgumentException: Invalid index: Cannot index property 'amount' into type List of Null
  • Hi,

    on you add link, add value it should be your cdt type.

    Now It's null, so system won't find the type.

    addRowlink: a!dynamicLink(
    
    label: "Add a new line.",
    
    value:type!<your CDT Name>(),
    
    saveInto: {
    
    a!save(
      local!input,
    
       append(
        local!input,
        save!value
       )
    
     )
    
    }
    
    )

     

    Thanks

    Vinay

  • Thanks Vinay,

    I have added the value parameter and a different error now shows whenever add a new row. See the error below.

    Here is the change I made:
    value: type!CSHV_Request_Data,

    However, when I saved, SAIL automatically converted it to:
    value: 'type!{urn:com:appian:types/CSHV}CSHV_Request_Data',

    New Error:
    Could not display interface. Please check definition and inputs.
    Interface Definition: Expression evaluation error at function a!forEach [line 212]: Error in a!forEach() expression during iteration 4: Expression evaluation error at function a!textField [line 218]: Invalid index: Cannot index property 'itemName' of type Text into type Type

    Thanks
  • Ok,

    seems the local!input type is anyType, try to convert into proper CDT type.

    local!input : cast(
    type!CSHV_Request_Data,
    <query entity>
    )
  • Thanks,

    Here is the new block of code:
    addRowlink: a!dynamicLink(
    label: "Add a new line.",
    value: cast(type!CSHV_Request_Data, local!input),
    saveInto: {
    a!save(
    local!input,
    append(
    local!input,
    save!value
    )
    )
    }
    )

    However, now, I get this error:
    Could not display interface. Please check definition and inputs.
    Interface Definition: Expression evaluation error at function a!forEach [line 212]: Error in a!forEach() expression during iteration 4: Expression evaluation error at function a!documentImage [line 308]: Invalid index: Cannot index property 'item' of type Text into type CSHV_Request_Data
  • The cast function is needed in addRowLink but u need to cast an empty or a null value as suggested by Vinay as you want to add a new row and request the data to be entered by the end user. Also you would need to cast local parameter local!input to the same type. Could you please check if item is one of the properties in your CDT or please share what do you need to display as the caption in the "Remove" column when you hover on the icon or image?
  • Hi Susan,

    Please try the below code snippet for addRowlink,

    addRowlink: a!dynamicLink(
      label: "Add a new line.",
      value: 'type!{urn:com:appian:types/CSHV}CSHV_Request_Data'(
        itemName: null,
        qty: null,
        amount: null,
        total: null
      ),
      saveInto: {
        a!save(
          local!input,
          append(
            local!input,
            save!value
          )
        )
      }
    )

     

    Thanks,

    Hema