Invalid index (5) for list: valid range is 1..4

Hi team,

When I am choosing multiple options at one particular time I am getting this error. Please help me to solve this error.

Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!forEach [line 42]: Error in a!forEach() expression during iteration 1: Expression evaluation error at function a!multipleDropdownField [line 199]: Invalid index (5) for list: valid range is 1..4

a!localVariables(
 local!pets:rule!SHA_refPets(),
  local!selectedValue:index(ri!pets, "petsIdFk", null()),
        local!originalArray: a!refreshVariable(
          value: local!selectedValue,
          refreshOnReferencedVarChange: false
        ),
        local!delete,
        local!insert,
        local!update,
        local!deleteCDT,
        local!insertCDT,
        local!updateCDT,
        local!mappingId:index(local!mappingKey,fv!index,null),
        {
          a!multipleDropdownField(
                        label: "Pets" ,
                        placeholder: "select a value",
                        choiceLabels: index(local!pets, "petsNm", null()),
                        choiceValues: index(local!pets, "petsId", null()),
                        value: local!selectedValue[wherecontains(true(),ri!pets.isActive)],
                        saveInto: {
                          local!selectedValue,
                          a!save(
                            local!update,
                            intersection(
                              tointeger(local!selectedValue),
                              tointeger(local!originalArray)
                            )
                          ),/*getting updated item*/
                          a!save(
                            local!delete,
                            difference(

                              tointeger(local!originalArray),
                              tointeger(local!selectedValue),
                            )
                          ),/*getting deleted item*/
                          a!save(
                            local!insert,
                            difference(
                              tointeger(local!selectedValue),
                              tointeger(local!originalArray),

                            )
                          ),/*getting new item*/
                          a!save(
                            local!insertCDT,
                            a!forEach(
                              items: local!insert,
                              expression: 'type!{urn:com:appian:types:SHA}SHA_newPets'(
                                petsId: null,
                                listingIdFk: index(ri!pets.listingIdFk, 1, null),
                                petsIdFk: fv!item,
                                mappingKey: null,
                                isActive: true
                              )
                            )
                          ),/*Creating CDT for new item*/
                          a!save(
                            local!deleteCDT,
                            index(
                              ri!pets,
                              wherecontains(
                                tointeger(local!delete),
                                tointeger(ri!pets.petsIdFk)
                              )
                            )
                          ),/*getting deleted index item*/
                          a!save(
                            local!deleteCDT,
                            a!forEach(
                              items: local!deleteCDT,
                              expression: 'type!{urn:com:appian:types:SHA}SHA_newPets'(
                                petsId: fv!item.petsId,
                                listingIdFk: fv!item.listingIdFk,
                                petsIdFk: fv!item.petsIdFk,
                                mappingKey: fv!item.mappingKey,
                                isActive: false,
                                createdBy: fv!item.createdBy
                              )
                            )
                          ),/*CDT Creation for Deleted item*/
                          a!save(
                            local!updateCDT,
                            index(
                              ri!pets,
                              wherecontains(
                                tointeger(local!update),
                                tointeger(ri!pets.petsIdFk)
                              )
                            )
                          ),/*getting updated item index*/
                          a!save(
                            ri!pets,
                            reject(
                              fn!isnull,
                              append(
                                local!updateCDT,
                                local!deleteCDT,
                                local!insertCDT
                              )
                            )
                          )/*Final*/
                        }
                      )
        }

  Discussion posts and replies are publicly visible

Parents Reply
  • 0
    Certified Lead Developer
    in reply to mamathak0001

    That isn't how the value parameter is intended to work, though.  What you've written will break, for the specific reason I noted.  If you want users to be unable to select certain values depending on background conditions, I suggest you handle that within a Validation, instead of messing with the choices or the current value.

    Also, you're executing a whole lot of logic in the saveInto of your multiple dropdown - these will all run every single time the selected value is changed.  I would strongly suggest that you move this logic into a button click or link, to be run only after the user's selections might be finalized.

Children