I am getting this error,"Interface Definition: Expression evaluation error [evaluation ID = c6a1e:375c5] : An error occurred while executing a save: java.lang.IllegalArgumentException: Invalid index type: Cannot index property '1' into diction

Certified Associate Developer

a!localVariables(
  local!transaction: index(
    rule!NW_getTransactionDataFromKongAPI(transactionId: ri!transactionId),
    1,
   {}
  ),
  {
    a!cardLayout(
      contents: {
        a!richTextDisplayField(
          value: {
            a!richTextItem(
              text: cons!NW_TXT_QUICK_ACTION_CASE_TYPE_UPDATE_SUITABILITY_STATUS,
              color: cons!NW_COLOR_WHITE,
              size: "MEDIUM_PLUS",
              style: "STRONG"
            )
          }
        )
      },
      height: "EXTRA_SHORT",
      style: cons!NW_COLOR_PRIMARY,
      marginBelow: "STANDARD"
    ),
    a!cardLayout(
      contents: {
        a!columnsLayout(
          columns: {
            a!columnLayout(
              contents: {
                a!dropdownField(
                  label: "Suitability Status",
                  labelPosition: "ADJACENT",
                  required: true(),
                  placeholder: "------Select Suitability Status from the below List----",
                  choiceLabels: {
                    "Approved",
                    "NC Non-Suitability Not Taken-HO Decision",
                    "NC Suitability Not taken-HO Decision",
                    "Non-Suitability Decline",
                    "Not Taken",
                    "Partial Approve",
                    "Pending",
                    "Suitability Decline"
                  },
                  choiceValues: {
                    "Approved",
                    "NC Non-Suitability Not Taken-HO Decision",
                    "NC Suitability Not taken-HO Decision",
                    "Non-Suitability Decline",
                    "Not Taken",
                    "Partial Approve",
                    "Pending",
                    "Suitability Decline"
                  },
                  value: local!transaction.suitability.decision_results[1].outcome,
                  saveInto: local!transaction.suitability.decision_results[1].outcome,
                  
                )
              }
            ),
            a!columnLayout(
              contents: {
                a!dropdownField(
                  label: "Decline Reasons",
                  required: true(),
                  labelPosition: "ADJACENT",
                  placeholder: "------Select Decline Reason from the below List----",
                  choiceLabels: {
                    "Advantages",
                    "CA Medi-Cal",
                    "CA Surrender Charges",
                    "Death Benefit Loss",
                    "Disability",
                    "Disadvantages",
                    "Does your Income cover all living expenses including medical",
                    "Do you have an emergency fund",
                    "High Annuity to net worth ratio",
                    "High Fixed Rate",
                    "Income Rider Loss",
                    "Income Rider VS Income Rider",
                    "Insufficient Replacement Reason",
                    "Internal Replacement Guidelines",
                    "I refuse",
                    "Is Not Based",
                    "Is your Income sufficient to cover future changes",
                    "Limited",
                    "Low Disposable Income",
                    "Low Liquid Assets",
                    "MN Recommendation Unsupported",
                    "MN Replacement not out of surrender term",
                    "MO Lookback",
                    "Nationwide under 36 months",
                    "Non-Resident",
                    "Non-US Funds",
                    "NY-Producer doesn't feel fixed annuity is in the customer's best interest",
                    "NY-Producer Limitations on products offered",
                    "NY-Producer feels product isn't in the customer's best interest",
                    "NY-Understanding of non-guaranteed elements",
                    "NY Reg60",
                    "NY Surrender Charges",
                    "Product Availability",
                    "Replacement prior to anniversary date",
                    "Replacement under 12 months",
                    "Replacement under 24 months",
                    "Reverse Mortgage",
                    "Suitability Client Call Issues",
                    "Surrender Charges",
                    "Unemployment",
                    "Watch Producer"
                  },
                  choiceValues: {
                    "Advantages",
                    "CA Medi-Cal",
                    "CA Surrender Charges",
                    "Death Benefit Loss",
                    "Disability",
                    "Disadvantages",
                    "Does your Income cover all living expenses including medical",
                    "Do you have an emergency fund",
                    "High Annuity to net worth ratio",
                    "High Fixed Rate",
                    "Income Rider Loss",
                    "Income Rider VS Income Rider",
                    "Insufficient Replacement Reason",
                    "Internal Replacement Guidelines",
                    "I refuse",
                    "Is Not Based",
                    "Is your Income sufficient to cover future changes",
                    "Limited",
                    "Low Disposable Income",
                    "Low Liquid Assets",
                    "MN Recommendation Unsupported",
                    "MN Replacement not out of surrender term",
                    "MO Lookback",
                    "Nationwide under 36 months",
                    "Non-Resident",
                    "Non-US Funds",
                    "NY-Producer doesn't feel fixed annuity is in the customer's best interest",
                    "NY-Producer Limitations on products offered",
                    "NY-Producer feels product isn't in the customer's best interest",
                    "NY-Understanding of non-guaranteed elements",
                    "NY Reg60",
                    "NY Surrender Charges",
                    "Product Availability",
                    "Replacement prior to anniversary date",
                    "Replacement under 12 months",
                    "Replacement under 24 months",
                    "Reverse Mortgage",
                    "Suitability Client Call Issues",
                    "Surrender Charges",
                    "Unemployment",
                    "Watch Producer"
                  },
                  value: local!transaction.suitability.decision_results[1].decline_reason,
                  saveInto: local!transaction.suitability.decision_results[1].decline_reason,
                  showWhen: contains(
                    {
                      "Suitability Decline",
                      "Non-Suitability Decline"
                    },
                    tostring(
                      local!transaction.suitability.decision_results[1].outcome
                    )
                  )
                )
              },
              
            )
          },
          alignVertical: "MIDDLE",
          marginAbove: "LESS",
          marginBelow: "EVEN_LESS"
        ),
        
      },
      height: "AUTO",
      style: "NONE",
      shape: "ROUNDED",
      padding: "STANDARD",
      marginBelow: "STANDARD",
      showBorder: false,
      showShadow: true,
      
    ),
    rule!NW_verticalSpacer(n: 1),
    rule!NW_verticalSpacer(n: 1),
    a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: 'translation!{765a2893-6d2c-4330-8d7a-ac85f4a6f417}CMGT_BaseTranslations.{0c9868e3-27cc-42e9-82cf-81687e0a1e6e}Complete',
          saveInto: {
            a!save(
              local!transaction.meta_data,
              a!update(
                local!transaction.meta_data,
                "hitl_outcome",
                ri!quickActionType
              )
            ),
            a!save(ri!jsonResponse, a!toJson(local!transaction)),
            a!save(
              ri!buttonValue,
              cons!NW_TEXT_BUTTON_LABEL_SUBMIT
            )
          },
          style: "SOLID",
          submit: true,
          validate: true,
          color: cons!NW_COLOR_BUTTONS,
          
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: 'translation!{765a2893-6d2c-4330-8d7a-ac85f4a6f417}CMGT_BaseTranslations.{651cf177-f30b-485b-900f-8aaf47805737}Cancel',
          style: "OUTLINE",
          submit: true,
          validate: false,
          value: true,
          saveInto: {
            a!save(
              ri!buttonValue,
              cons!NW_TEXT_BUTTON_LABEL_CANCEL
            )
          }
        )
      },
      
    )
  }
)

I am getting above error,when response from integration does not decsion_results in structure and user wants to update it, I am trying to find a solution so that in both the cases when value is there it should display and user can update it based on dropdown as well as if it is not there it should get updated in response.please help me regarding this scenario

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    In the value parameter, you will have to check whether that first item in the list exists.

    In the saveInto, update an existing item, or, if none exists, append a new element to that list containing the selected value.

  • 0
    Certified Lead Developer

    The issue is that saveInto cannot save to an array index that doesn't exist. When decision_results is missing, system can't save to [1].outcome because there's no array to index into. The solution is to modify your saveInto to first check if decision_results exists using property() function, and if it doesn't exist, create the entire nested structure with a!update() including the array with your value; if it does exist, then update the existing array index. This conditional approach ensures the structure is created when needed during the save operation, preventing the index error while allowing updates to work in both scenarios, When the API returns data with or without the decision_results array.