Skip to main content
thulasik7152
January 3, 2023
Question

How to resolve nested loop issue

  • January 3, 2023
  • 6 replies
  • 0 views

Here I have a Plan Type
Within Plan Type Sum Insured (Min Val and Max Val)
Within Sum Insured Year Range (Min Year and Max Year)
Within Year Range service center (Agency or Garage)
1. I should be able to duplicate the whole transaction
2. I should be able to add multiple Sum Insured (Min Val and Max Val).
3. When I add this, within Sum Insured I should be able to add multiple Year Range
4. Within the Year Range I should be able to add multiple service centers ( 1 Agency and 1 Garage)
Now with the current code If I add a Transaction, 2 Transactions are getting added
After filling details if I add another transaction, all the values getting disappeared from the 1st transaction
If I add Year Range I am getting the following error message (An error occurred while executing a save: Expression evaluation error at a function a!map parameter 3 [line 328]: Cannot add incompatible operands of type Null and type Number (Integer).)

a!localVariables(
  local!index: 1,
  local!planType: {a!map(planType: "", index: local!index)},
  local!sumIns: {
    a!map(
      minValSi: "",
      maxValSi: "",
      sumIndex: local!index,
      index: local!index
    )
  },
  local!yrRange: {
    a!map(
      minYear: "",
      maxYear: "",
      yrIndex: local!index,
      index: local!index
    )
  },
  local!sumInsTrans: {
    a!map(
      agency: "",
      percentage: "",
      flat: "",
      minimumPremium: "",
      excess: "",
      suminsIndex: local!index,
      index: local!index
    )
  },
  local!extension: {
    a!map(
      extncover: "",
      mndtoptn: "",
      relsumins: "",
      flat_ext: "",
      percentage_ext: "",
      index: local!index
    )
  },
  {
    a!richTextDisplayField(
      align: "RIGHT",
      value: {
        a!richTextItem(
          text: { "New Transaction" },
          color: "ACCENT",
          size: "MEDIUM",
          style: "STRONG"
        ),

      },
    ),
    a!richTextDisplayField(
      value: a!richTextIcon(
        icon: "plus",
        altText: "New",
        size: "MEDIUM",
        link: a!dynamicLink(
          saveInto: {
            a!save(
              
             local!planType,
              append(
                local!planType,
                a!map(
                  planType: "",
                  index: local!index + count(local!planType)
                )
              )
            ),
            a!save(
              local!sumIns,
              append(
                local!sumIns,
                a!map(
                  minValSi: "",
                  maxValSi: "",
                  sumIndex: local!index + 1,
                  index: local!index + count(local!sumIns)
                )
              )
            ),
            a!save(
              local!yrRange,
              append(
                local!yrRange,
                a!map(
                  minYear: "",
                  maxYear: "",
                  yrIndex: local!index + 1,
                  index: local!index + count(local!yrRange)
                )
              )
            ),
            a!save(
              local!sumInsTrans,
              append(
                local!sumInsTrans,
                a!map(
                  agency: "",
                  percentage: "",
                  flat: "",
                  minimumPremium: "",
                  excess: "",
                  suminsIndex: local!index + 1,
                  index: local!index + count(local!sumInsTrans)
                )
              )
            ),
            a!save(
              local!extension,
              append(
                local!extension,
                a!map(
                  extncover: "",
                  mndtoptn: "",
                  relsumins: "",
                  flat_ext: "",
                  percentage_ext: "",
                  index: local!index + count(local!extension)
                )
              )
            ),
            a!save(
              ri!planType,
              local!planType
            ),
            a!save(
              ri!sumins,
              local!sumIns
            ),
            a!save(
              ri!yrRange,
              local!yrRange
            ),
            a!save(
              ri!sumInsTrans,
              local!sumInsTrans
            ),
            a!save(
              ri!extension,
              local!extension
            )
          }
        )
      ),
      align: "RIGHT"
    ),
    a!forEach(
      items: ri!planType,
      expression: a!cardLayout(
        contents: {
          a!richTextDisplayField(
            value: {
              a!richTextItem(
                text: { "Plan Type" },
                color: "ACCENT",
                size: "MEDIUM",
                style: "STRONG"
              ),
              
            }
          ),
          a!dropdownField(
            label: "",
            placeholder: " ",
            choiceLabels: { "Platinum", "Gold", "Silver" },
            choiceValues: { "Platinum", "Gold", "Silver" },
            value: index(fv!item, "planType", null),
            saveInto: {
              fv!item.planType,
              /*a!save(ri!ratingTransaction,save!value)*/
              
            }
          ),
          a!richTextDisplayField(
            value: {
              a!richTextItem(
                text: { "Sum Insured" },
                color: "ACCENT",
                size: "MEDIUM",
                style: "STRONG"
              ),
              
            }
          ),
          a!richTextDisplayField(
            value: a!richTextIcon(
              icon: "plus",
              link: a!dynamicLink(
                saveInto: {
                  a!save(
                    local!sumIns,
                    append(
                      local!sumIns,
                      a!map(
                        minValSi: "",
                        maxValSi: "",
                        sumIndex: local!index + 1,
                        index: index(fv!item, "index", null)
                      )
                    )
                  ),
                  a!save(
                    local!yrRange,
                    append(
                      local!yrRange,
                      a!map(
                        minYear: "",
                        maxYear: "",
                        yrIndex: local!index,
                        index: count(local!sumIns)
                      )
                    )
                  ),
                  a!save(
                    local!sumInsTrans,
                    append(
                      local!sumInsTrans,
                      a!map(
                        agency: "",
                        percentage: "",
                        flat: "",
                        minimumPremium: "",
                        excess: "",
                        suminsIndex: local!index,
                        index: count(local!yrRange)
                      )
                    )
                  ),
                  a!save(
                    ri!sumins,
                    local!sumIns
                  ),
                  a!save(
                    ri!yrRange,
                    local!yrRange
                  ),
                  a!save(
                    ri!sumInsTrans,
                    local!sumInsTrans
                  ),
                  a!save(
                    ri!extension,
                    local!extension
                  )
                }
              ),
              linkStyle: "STANDALONE"
            ),
            align: "RIGHT"
          ),
          a!forEach(
            items: ri!sumins[wherecontains(
              index(fv!item, "index", null), index(ri!sumins, "index", null)
            )],
            expression: a!cardLayout(
              contents: {
                a!columnsLayout(
                  columns: {
                    a!columnLayout(
                      contents: {
                        a!textField(
                          label: "Minimum Value",
                          value: index(fv!item, "minValSi", ""),
                          saveInto: fv!item.minValSi,
                          readOnly: ri!readOnly,
                          
                        )
                      }
                    ),
                    a!columnLayout(
                      contents: {
                        a!textField(
                          label: "Maximum Value",
                          value: index(fv!item, "maxValSi", ""),
                          saveInto: fv!item.maxValSi,
                          readOnly: ri!readOnly,
                          
                        )
                      }
                    ),
                    a!columnLayout(
                      contents: a!richTextDisplayField(
                        value: {
                          char(10),
                          a!richTextIcon(
                            icon: "remove",
                            color: "NEGATIVE",
                            link: a!dynamicLink(
                              saveInto: a!save(
                                ri!sumins,
                                remove(local!sumIns, fv!index)
                              )
                            ),
                            linkStyle: "STANDALONE"
                          )
                        }
                      ),
                      width: "EXTRA_NARROW"
                    )
                  }
                ),
                a!richTextDisplayField(
                  value: {
                    a!richTextItem(
                      text: { "Year Range" },
                      color: "ACCENT",
                      size: "MEDIUM",
                      style: "STRONG"
                    ),
                    
                  }
                ),
                a!richTextDisplayField(
                  value: a!richTextIcon(
                    icon: "plus",
                    link: a!dynamicLink(
                      saveInto: {
                        a!save(
                          local!yrRange,
                          append(
                            local!yrRange,
                            a!map(
                              minYear: "",
                              maxYear: "",
                              yrIndex: index(fv!item, "yrIndex", null) + 1,
                              index: index(fv!item, "index", null)
                            )
                          )
                        ),
                        a!save(
                          local!sumInsTrans,
                          append(
                            local!sumInsTrans,
                            a!map(
                              agency: "",
                              percentage: "",
                              flat: "",
                              minimumPremium: "",
                              excess: "",
                              suminsIndex: index(fv!item, "suminsIndex", null) + 1,
                              index: index(fv!item, "index", null)
                            )
                          )
                        ),
                        a!save(
                          ri!yrRange,
                          local!yrRange
                        ),
                        a!save(
                          ri!sumInsTrans,
                          local!sumInsTrans
                        )
                      }
                    ),
                    linkStyle: "STANDALONE"
                  ),
                  align: "RIGHT"
                ),
                a!cardLayout(
                  contents: {
                    a!forEach(
                      items: ri!yrRange[wherecontains(
                        index(fv!item, "index", null), index(ri!yrRange, "yrIndex", null)
                      )],
                      expression: {
                        a!columnsLayout(
                          columns: {
                            a!columnLayout(
                              contents: {
                                a!dateField(
                                  label: "Minimum Year",
                                  labelPosition: "ABOVE",
                                  value: index(fv!item, "minYr", ""),
                                  saveInto: fv!item.minYr,
                                  validations: {}
                                )
                              }
                            ),
                            a!columnLayout(
                              contents: {
                                a!dateField(
                                  label: "Maximum Year",
                                  labelPosition: "ABOVE",
                                  value: index(fv!item, "maxYr", ""),
                                  saveInto: fv!item.maxYr,
                                  validations: {}
                                )
                              }
                            ),
                            a!columnLayout(
                              contents: a!richTextDisplayField(
                                value: {
                                  char(10),
                                  a!richTextIcon(
                                    icon: "remove",
                                    link: a!dynamicLink(
                                      saveInto: a!save(
                                        ri!yrRange,
                                        remove(local!yrRange, fv!index)
                                      )
                                    ),
                                    linkStyle: "STANDALONE",
                                    color: "NEGATIVE"
                                  )
                                }
                              ),
                              width: "EXTRA_NARROW"
                            )
                          }
                        ),
                        a!forEach(
                          items: ri!sumInsTrans[wherecontains(
                            index(fv!item, "index", null), tointeger(index(ri!sumInsTrans, "index", null))
                          )],
                          expression: a!cardLayout(
                            contents: {
                              a!columnsLayout(
                                columns: {
                                  a!columnLayout(
                                    contents: {
                                      a!radioButtonField(
                                        label: "Agency",
                                        choiceLabels: { " Agency", "Garage" },
                                        choiceValues: { true(), false() },
                                        value: index(fv!item, "isAgency", ""),
                                        saveInto: fv!item.isAgency,
                                        disabled: ri!readOnly,
                                        choiceLayout: "COMPACT",
                                        choiceStyle: "STANDARD"
                                      )
                                    }
                                  ),
                                  a!columnLayout(
                                    contents: {
                                      a!textField(
                                        label: "Percentage",
                                        value: index(fv!item, "percentage", ""),
                                        saveInto: fv!item.percentage,
                                        readOnly: ri!readOnly,
                                        disabled: fv!item.flat
                                      )
                                    }
                                  ),
                                  a!columnLayout(
                                    contents: {
                                      a!integerField(
                                        label: "Flat",
                                        value: index(fv!item, "flat", ""),
                                        saveInto: fv!item.flat,
                                        readOnly: ri!readOnly,
                                        disabled: fv!item.percentage
                                      )
                                    }
                                  ),
                                  a!columnLayout(
                                    contents: {
                                      a!textField(
                                        label: "Minimum Premium",
                                        value: index(fv!item, "minimumPremium", ""),
                                        saveInto: fv!item.minimumPremium,
                                        readOnly: ri!readOnly
                                      )
                                    }
                                  ),
                                  a!columnLayout(
                                    contents: {
                                      a!textField(
                                        label: "Excess",
                                        value: index(fv!item, "excess", ""),
                                        saveInto: fv!item.excess,
                                        readOnly: ri!readOnly
                                      )
                                    }
                                  ),
                                  a!columnLayout(
                                    contents: a!richTextDisplayField(
                                      value: {
                                        char(10),
                                        a!richTextIcon(
                                          icon: "remove",
                                          link: a!dynamicLink(
                                            saveInto: a!save(
                                              ri!sumInsTrans,
                                              remove(local!sumInsTrans, fv!index)
                                            )
                                          ),
                                          linkStyle: "STANDALONE",
                                          color: "NEGATIVE"
                                        )
                                      }
                                    ),
                                    width: "EXTRA_NARROW"
                                  )
                                }
                              )
                            }
                          )
                        ),
                        a!richTextDisplayField(
                          value: a!richTextItem(
                            text: "+ Add new row",
                            link: a!dynamicLink(
                              saveInto: a!save(
                                ri!sumInsTrans,
                                append(
                                  ri!sumInsTrans,
                                  a!map(
                                    isAgency: "",
                                    percentage: "",
                                    flat: "",
                                    minimumPremium: "",
                                    excess: "",
                                    suminsIndex: index(
                                      ri!sumInsTrans[wherecontains(
                                        index(fv!item, "index", null), index(ri!sumInsTrans, "index", null)
                                      )],
                                      1,
                                      "suminsIndex",
                                      null
                                    ) + 1,
                                    index: index(fv!item, "index", "")
                                  )
                                )
                              )
                            ),
                            style: "STRONG"
                          )
                        )
                      }
                    )
                  }
                ),
                
              }
            )
          ),
          a!cardLayout(
            contents: {
              a!richTextDisplayField(
                value: a!richTextItem(
                  text: "Coverage Extension",
                  style: "STRONG",
                  size: "MEDIUM",
                  color: "ACCENT"
                )
              ),
              a!forEach(
                items: ri!extension[wherecontains(
                  index(fv!item, "index", null), index(ri!extension, "index", null)
                )],
                expression: a!columnsLayout(
                  columns: {
                    a!columnLayout(
                      contents: {
                        a!dropdownField(
                          label: "Extension Coverage",
                          placeholder: "select extension",
                          choiceLabels: {
                            "Medical Coverage",
                            "Travel Inco Coverage",
                            "Terrorism Coverage",
                            "Haz sport coverage",
                            "Personal Accident",
                            
                          },
                          choiceValues: { 1, 2, 3, 4, 5 },
                          value: index(fv!item, "extncover", ""),
                          saveInto: fv!item.extncover,
                          disabled: ri!readonly,
                          validations: if(
                            count(
                              wherecontains(
                                tointeger(index(fv!item, "extncover", "")),
                                tointeger(
                                  index(
                                    ri!extension[wherecontains(
                                      index(fv!item, "index", null), index(ri!extension, "index", null)
                                    )],
                                    "extncover",
                                    null
                                  )
                                )
                              )
                            ) > 1,
                            "Extension Already exists",
                            null
                          )
                        )
                      }
                    ),
                    a!columnLayout(
                      contents: {
                        a!dropdownField(
                          label: "Mandatory",
                          placeholder: " ",
                          choiceLabels: { "Mandatory", "Optional" },
                          choiceValues: { true(), false() },
                          value: index(fv!item, "mndtoptn", null),
                          saveInto: fv!item.mndtoptn,
                          disabled: ri!readonly
                        )
                      }
                    ),
                    /*a!columnLayout(*/
                      /*contents: {*/
                        /*a!textField(*/
                          /*label: "Relational Sum Insurred",*/
                          /*value: index(fv!item, "relsumins", ""),*/
                          /*saveInto: fv!item.relsumins,*/
                          /*readOnly:  ri!readonly*/
                        /*)*/
                      /*}*/
                    /*),*/
                    a!columnLayout(
                      contents: {
                        a!textField(
                          label: "Flat",
                          placeholder: " ",
                          value: index(fv!item, "flat_ext", ""),
                          saveInto: fv!item.flat_ext,
                            disabled: fv!item.percentage_ext,
                            readOnly: ri!readonly
                        )
                      }
                    ),
                    a!columnLayout(
                      contents: {
                        a!textField(
                          label: "Percentage",
                          value: index(fv!item, "percentage_ext", ""),
                          saveInto: fv!item.percentage_ext,
                          disabled: fv!item.flat_ext,
                          readOnly: ri!readonly
                        )
                      }
                    ),
                    a!columnLayout(
                      contents: a!richTextDisplayField(
                        value: {
                          char(10),
                          a!richTextIcon(
                            icon: "remove",
                            color: "NEGATIVE",
                            link: a!dynamicLink(
                              saveInto: a!save(
                                ri!extension,
                                remove(ri!extension, fv!index)
                              )
                            ),
                            linkStyle: "STANDALONE"
                          )
                        }
                      ),
                      width: "EXTRA_NARROW"
                    )
                  }
                )
              ),
              a!richTextDisplayField(
                value: a!richTextItem(
                  text: "+ Add New Row",
                  style: "STRONG",
                  link: a!dynamicLink(
                    saveInto: {
                      a!save(
                        ri!extension,
                        append(
                          ri!extension,
                          a!map(
                            extncover: "",
                            mndtoptn: "",
                            relsumins: "",
                            flat_ext: "",
                            percentage_ext: "",
                            index: index(fv!item, "index", null)
                          )
                        )
                      )
                    }
                  )
                )
              )
            }
          )
        },
        height: "AUTO",
        style: "NONE",
        shape: "ROUNDED",
        padding: "MORE",
        marginBelow: "LESS",
        showWhen: ri!showWhen
      )
    )
  }
)

6 replies

peter.lewis
Employee
January 3, 2023

It's a little hard to follow this example - would it be possible to add a simplified version of the code that doesn't have any rule inupts that we could more easily test? For example, could you isolate the problem to a single save rather than sharing your whole interface?

thulasik7152
January 4, 2023

Hi [mention:6b9f80ff18f9420082d13ef2d5121d56:e9ed411860ed4f2ba0265705b8793d05]

Please add the below rule inputs in your test interface to test

sumins >> datatype - Map >> Array multiple

yrRange >> datatype - Map >> Array multiple

sumInsTrans >> datatype - Map >> Array multiple

extension >> datatype - Map >> Array multiple

planType >> datatype - Map >> Array multiple

readonly >> datatype - Boolean

richardm900458
January 3, 2023

hint: please try to write in full sentences instead just bullet points.

okay lets cute this into smaller issues:
in line 328: yrIndex: index(fv!item, "yrIndex", null) + 1,

is failing because you try to add null + 1. first step should be perhaps a version of  index(fv!item, "yrIndex", 0)

2.) the adding two lines instead of 1 item, this is a separate issue.

your line 505

                            a!dynamicLink(
                              saveInto: a!save(
                                target: ri!sumInsTrans,
                                value: append(
                                  ri!sumInsTrans,
                                  a!map(
                                    isAgency: "",
                                    percentage: "",
                                    flat: "",
                                    minimumPremium: "",
                                    excess: "",
                                    suminsIndex: index(
                                      ri!sumInsTrans[
                                          wherecontains(
                                            index(fv!item, "index", null), 
                                            index(ri!sumInsTrans, "index", null)
                                        )
                                      ],
                                      1,
                                      "suminsIndex",
                                      null
                                    ) + 1,
                                    index: index(fv!item, "index", "")
                                  )
                                )

i have a hard time to even understand the target.
index has 4 parameter -> ?

peter.lewis
Employee
January 6, 2023

Ok I just took a look at this and the reason you're getting two transactions added is that you have defined all of your local variables to start with an initial value. Then, you append a new value to them when clicking the plus and save that new result into the rule input. I would suggest just not initializing your local variables with any values.

thulasik7152
January 10, 2023

Now getting two transactions issue has been resolved. But there is another issue.

Scenario:

Click on New Transaction "+"

Add Dates for Year Range (Minimum Year and Maximum Year)

Add Values for Sum Insured Transaction Values (Agency, Percentage, Flat, Minimum Premium and Excess)

Now click on "+Add new row". A new Sum Insured Transaction row will be added

This time choose a different value from Agency and update the values

Now click on Year Range "+"

Here is the issue. Values are getting replicated from the previous transaction and additionally, there is a row getting inserted for Sum Insured Transaction for both transactions.

Please refer newly inserted code. Thank you!

a!localVariables(
  local!index: 1,
  {
    a!richTextDisplayField(
      align: "RIGHT",
      value: {
        a!richTextItem(
          text: { "New Transaction" },
          color: "ACCENT",
          size: "MEDIUM",
          style: "STRONG"
        ),
        
      },
      
    ),
    a!richTextDisplayField(
      value: a!richTextIcon(
        icon: "plus",
        altText: "New",
        size: "MEDIUM",
        link: a!dynamicLink(
          saveInto: {
            a!save(
              ri!planType,
              append(
                ri!planType,
                a!map(
                  planType: "",
                  index: if(
                    rule!APN_isEmpty(ri!plantype),
                    1,
                    count(ri!planType)+1
                  )
                )
              )
            ),
            a!save(
              ri!sumins,
              append(
                ri!sumins,
                a!map(
                  minValSi: "",
                  maxValSi: "",
                  sumIndex: local!index + 1,
                  index: if(
                    rule!APN_isEmpty(ri!sumins),
                    1,
                    count(ri!sumins) + 1
                  )
                )
              )
            ),
            a!save(
              ri!yrRange,
              append(
                ri!yrRange,
                a!map(
                  minYear: "",
                  maxYear: "",
                  yrIndex: local!index + 1,
                  index: if(
                    rule!APN_isEmpty(ri!yrRange),
                    1,
                    count(ri!yrRange) + 1
                  )
                )
              )
            ),
            a!save(
              ri!sumInsTrans,
              append(
                ri!sumInsTrans,
                a!map(
                  agency: "",
                  percentage: "",
                  flat: "",
                  minimumPremium: "",
                  excess: "",
                  suminsIndex: local!index + 1,
                  index: if(
                    rule!APN_isEmpty(ri!sumInsTrans),
                    1,
                    count(ri!sumInsTrans) + 1
                  )
                )
              )
            ),
            a!save(
              ri!extension,
              append(
                ri!extension,
                a!map(
                  extncover: "",
                  mndtoptn: "",
                  relsumins: "",
                  flat_ext: "",
                  percentage_ext: "",
                  index: if(
                    rule!APN_isEmpty(ri!extension),
                    1,
                    count(ri!extension) + 1
                  )
                )
              )
            )
          }
        )
      ),
      align: "RIGHT"
    ),
    a!forEach(
      items: ri!planType,
      expression: a!cardLayout(
        contents: {
          a!richTextDisplayField(
            value: {
              a!richTextItem(
                text: { "Plan Type" },
                color: "ACCENT",
                size: "MEDIUM",
                style: "STRONG"
              ),
              
            }
          ),
          a!dropdownField(
            label: "",
            placeholder: " ",
            choiceLabels: { "Platinum", "Gold", "Silver" },
            choiceValues: { "Platinum", "Gold", "Silver" },
            value: index(fv!item, "planType", null),
            saveInto: { fv!item.planType,  }
          ),
          a!richTextDisplayField(
            value: {
              a!richTextItem(
                text: { "Sum Insured" },
                color: "ACCENT",
                size: "MEDIUM",
                style: "STRONG"
              ),
              
            }
          ),
          a!richTextDisplayField(
            value: a!richTextIcon(
              icon: "plus",
              link: a!dynamicLink(
                saveInto: {
                  a!save(
                    ri!sumins,
                    append(
                      ri!sumins,
                      a!map(
                        minValSi: "",
                        maxValSi: "",
                        sumIndex: local!index + 1,
                        index: index(fv!item, "index", null)
                      )
                    )
                  ),
                  a!save(
                    ri!yrRange,
                    append(
                      ri!yrRange,
                      a!map(
                        minYear: "",
                        maxYear: "",
                        yrIndex: local!index,
                        index: count(ri!sumins)
                      )
                    )
                  ),
                  a!save(
                    ri!sumInsTrans,
                    append(
                      ri!sumInsTrans,
                      a!map(
                        agency: "",
                        percentage: "",
                        flat: "",
                        minimumPremium: "",
                        excess: "",
                        suminsIndex: local!index,
                        index: count(ri!yrRange)
                      )
                    )
                  )
                }
              ),
              linkStyle: "STANDALONE"
            ),
            align: "RIGHT"
          ),
          a!forEach(
            items: ri!sumins[wherecontains(
              index(fv!item, "index", null), index(ri!sumins, "index", null)
            )],
            expression: a!cardLayout(
              contents: {
                a!columnsLayout(
                  columns: {
                    a!columnLayout(
                      contents: {
                        a!textField(
                          label: "Minimum Value",
                          value: index(fv!item, "minValSi", ""),
                          saveInto: fv!item.minValSi,
                          readOnly: ri!readOnly,
                          
                        )
                      }
                    ),
                    a!columnLayout(
                      contents: {
                        a!textField(
                          label: "Maximum Value",
                          value: index(fv!item, "maxValSi", ""),
                          saveInto: fv!item.maxValSi,
                          readOnly: ri!readOnly,
                          
                        )
                      }
                    ),
                    a!columnLayout(
                      contents: a!richTextDisplayField(
                        value: {
                          char(10),
                          a!richTextIcon(
                            icon: "remove",
                            color: "NEGATIVE",
                            link: a!dynamicLink(
                              saveInto: a!save(ri!sumins, remove(ri!sumins, fv!index))
                            ),
                            linkStyle: "STANDALONE"
                          )
                        }
                      ),
                      width: "EXTRA_NARROW"
                    )
                  }
                ),
                a!richTextDisplayField(
                  value: {
                    a!richTextItem(
                      text: { "Year Range" },
                      color: "ACCENT",
                      size: "MEDIUM",
                      style: "STRONG"
                    ),
                    
                  }
                ),
                a!richTextDisplayField(
                  value: a!richTextIcon(
                    icon: "plus",
                    link: a!dynamicLink(
                      saveInto: {
                        a!save(
                          ri!yrRange,
                          append(
                            ri!yrRange,
                            a!map(
                              minYear: "",
                              maxYear: "",
                              yrIndex: tointeger(index(fv!item, "yrIndex", null)) + 1,
                              index: index(fv!item, "index", null)
                            )
                          )
                        ),
                        a!save(
                          ri!sumInsTrans,
                          append(
                            ri!sumInsTrans,
                            a!map(
                              agency: "",
                              percentage: "",
                              flat: "",
                              minimumPremium: "",
                              excess: "",
                              suminsIndex: tointeger(index(fv!item, "suminsIndex", null)) + 1,
                              index: index(fv!item, "index", null)
                            )
                          )
                        )
                      }
                    ),
                    linkStyle: "STANDALONE"
                  ),
                  align: "RIGHT"
                ),
                a!cardLayout(
                  contents: {
                    a!forEach(
                      items: ri!yrRange[wherecontains(
                        index(fv!item, "index", null), index(ri!yrRange, "index", null)
                      )],
                      expression: {
                        a!columnsLayout(
                          columns: {
                            a!columnLayout(
                              contents: {
                                a!dateField(
                                  label: "Minimum Year",
                                  labelPosition: "ABOVE",
                                  value: index(fv!item, "minYr", ""),
                                  saveInto: fv!item.minYr,
                                  validations: {}
                                )
                              }
                            ),
                            a!columnLayout(
                              contents: {
                                a!dateField(
                                  label: "Maximum Year",
                                  labelPosition: "ABOVE",
                                  value: index(fv!item, "maxYr", ""),
                                  saveInto: fv!item.maxYr,
                                  validations: {}
                                )
                              }
                            ),
                            a!columnLayout(
                              contents: a!richTextDisplayField(
                                value: {
                                  char(10),
                                  a!richTextIcon(
                                    icon: "remove",
                                    link: a!dynamicLink(
                                      saveInto: a!save(ri!yrRange, remove(ri!yrRange, fv!index))
                                    ),
                                    linkStyle: "STANDALONE",
                                    color: "NEGATIVE"
                                  )
                                }
                              ),
                              width: "EXTRA_NARROW"
                            )
                          }
                        ),
                        a!forEach(
                          items: ri!sumInsTrans[wherecontains(
                            index(fv!item, "index", null), tointeger(index(ri!sumInsTrans, "index", null))
                          )],
                          expression: a!cardLayout(
                            contents: {
                              a!columnsLayout(
                                columns: {
                                  a!columnLayout(
                                    contents: {
                                      a!radioButtonField(
                                        label: "Agency",
                                        choiceLabels: { " Agency", "Garage" },
                                        choiceValues: { true(), false() },
                                        value: index(fv!item, "isAgency", ""),
                                        saveInto: fv!item.isAgency,
                                        disabled: ri!readOnly,
                                        choiceLayout: "COMPACT",
                                        choiceStyle: "STANDARD"
                                      )
                                    }
                                  ),
                                  a!columnLayout(
                                    contents: {
                                      a!textField(
                                        label: "Percentage",
                                        value: index(fv!item, "percentage", ""),
                                        saveInto: fv!item.percentage,
                                        readOnly: ri!readOnly,
                                        disabled: fv!item.flat
                                      )
                                    }
                                  ),
                                  a!columnLayout(
                                    contents: {
                                      a!integerField(
                                        label: "Flat",
                                        value: index(fv!item, "flat", ""),
                                        saveInto: fv!item.flat,
                                        readOnly: ri!readOnly,
                                        disabled: fv!item.percentage
                                      )
                                    }
                                  ),
                                  a!columnLayout(
                                    contents: {
                                      a!textField(
                                        label: "Minimum Premium",
                                        value: index(fv!item, "minimumPremium", ""),
                                        saveInto: fv!item.minimumPremium,
                                        readOnly: ri!readOnly
                                      )
                                    }
                                  ),
                                  a!columnLayout(
                                    contents: {
                                      a!textField(
                                        label: "Excess",
                                        value: index(fv!item, "excess", ""),
                                        saveInto: fv!item.excess,
                                        readOnly: ri!readOnly
                                      )
                                    }
                                  ),
                                  a!columnLayout(
                                    contents: a!richTextDisplayField(
                                      value: {
                                        char(10),
                                        a!richTextIcon(
                                          icon: "remove",
                                          link: a!dynamicLink(
                                            saveInto: a!save(
                                              ri!sumInsTrans,
                                              remove(ri!sumInsTrans, fv!index)
                                            )
                                          ),
                                          linkStyle: "STANDALONE",
                                          color: "NEGATIVE"
                                        )
                                      }
                                    ),
                                    width: "EXTRA_NARROW"
                                  )
                                }
                              )
                            }
                          )
                        ),
                        a!richTextDisplayField(
                          value: a!richTextItem(
                            text: "+ Add new row",
                            link: a!dynamicLink(
                              saveInto: a!save(
                                ri!sumInsTrans,
                                append(
                                  ri!sumInsTrans,
                                  a!map(
                                    isAgency: "",
                                    percentage: "",
                                    flat: "",
                                    minimumPremium: "",
                                    excess: "",
                                    suminsIndex: index(
                                      ri!sumInsTrans[wherecontains(
                                        index(fv!item, "index", null), index(ri!sumInsTrans, "index", null)
                                      )],
                                      1,
                                      "suminsIndex",
                                      null
                                    ) ,
                                    index: index(fv!item, "index", "")
                                  )
                                )
                              )
                            ),
                            style: "STRONG"
                          )
                        )
                      }
                    )
                  }
                ),
                
              }
            )
          ),
          a!cardLayout(
            contents: {
              a!richTextDisplayField(
                value: a!richTextItem(
                  text: "Coverage Extension",
                  style: "STRONG",
                  size: "MEDIUM",
                  color: "ACCENT"
                )
              ),
              a!forEach(
                items: ri!extension[wherecontains(
                  index(fv!item, "index", null), index(ri!extension, "index", null)
                )],
                expression: a!columnsLayout(
                  columns: {
                    a!columnLayout(
                      contents: {
                        a!dropdownField(
                          label: "Extension Coverage",
                          placeholder: "select extension",
                          choiceLabels: {
                            "Medical Coverage",
                            "Travel Inco Coverage",
                            "Terrorism Coverage",
                            "Haz sport coverage",
                            "Personal Accident",
                            
                          },
                          choiceValues: { 1, 2, 3, 4, 5 },
                          value: index(fv!item, "extncover", ""),
                          saveInto: fv!item.extncover,
                          disabled: ri!readonly,
                          validations: if(
                            count(
                              wherecontains(
                                tointeger(index(fv!item, "extncover", "")),
                                tointeger(
                                  index(
                                    ri!extension[wherecontains(
                                      index(fv!item, "index", null), index(ri!extension, "index", null)
                                    )],
                                    "extncover",
                                    null
                                  )
                                )
                              )
                            ) > 1,
                            "Extension Already exists",
                            null
                          )
                        )
                      }
                    ),
                    a!columnLayout(
                      contents: {
                        a!dropdownField(
                          label: "Mandatory",
                          placeholder: " ",
                          choiceLabels: { "Mandatory", "Optional" },
                          choiceValues: { true(), false() },
                          value: index(fv!item, "mndtoptn", null),
                          saveInto: fv!item.mndtoptn,
                          disabled: ri!readonly
                        )
                      }
                    ),
                    /*a!columnLayout(*/
                    /*contents: {*/
                    /*a!textField(*/
                    /*label: "Relational Sum Insurred",*/
                    /*value: index(fv!item, "relsumins", ""),*/
                    /*saveInto: fv!item.relsumins,*/
                    /*readOnly:  ri!readonly*/
                    /*)*/
                    /*}*/
                    /*),*/
                    a!columnLayout(
                      contents: {
                        a!textField(
                          label: "Flat",
                          placeholder: " ",
                          value: index(fv!item, "flat_ext", ""),
                          saveInto: fv!item.flat_ext,
                          disabled: fv!item.percentage_ext,
                          readOnly: ri!readonly
                        )
                      }
                    ),
                    a!columnLayout(
                      contents: {
                        a!textField(
                          label: "Percentage",
                          value: index(fv!item, "percentage_ext", ""),
                          saveInto: fv!item.percentage_ext,
                          disabled: fv!item.flat_ext,
                          readOnly: ri!readonly
                        )
                      }
                    ),
                    a!columnLayout(
                      contents: a!richTextDisplayField(
                        value: {
                          char(10),
                          a!richTextIcon(
                            icon: "remove",
                            color: "NEGATIVE",
                            link: a!dynamicLink(
                              saveInto: a!save(
                                ri!extension,
                                remove(ri!extension, fv!index)
                              )
                            ),
                            linkStyle: "STANDALONE"
                          )
                        }
                      ),
                      width: "EXTRA_NARROW"
                    )
                  }
                )
              ),
              a!richTextDisplayField(
                value: a!richTextItem(
                  text: "+ Add New Row",
                  style: "STRONG",
                  link: a!dynamicLink(
                    saveInto: {
                      a!save(
                        ri!extension,
                        append(
                          ri!extension,
                          a!map(
                            extncover: "",
                            mndtoptn: "",
                            relsumins: "",
                            flat_ext: "",
                            percentage_ext: "",
                            index: index(fv!item, "index", null)
                          )
                        )
                      )
                    }
                  )
                )
              )
            }
          )
        },
        height: "AUTO",
        style: "NONE",
        shape: "ROUNDED",
        padding: "MORE",
        marginBelow: "LESS",
        showWhen: ri!showWhen
      )
    )
  }
)

Please add the below rule inputs in your test interface to test

sumins >> datatype - Map >> Array multiple

yrRange >> datatype - Map >> Array multiple

sumInsTrans >> datatype - Map >> Array multiple

extension >> datatype - Map >> Array multiple

planType >> datatype - Map >> Array multiple

readonly >> datatype - Boolean

peter.lewis
Employee
January 10, 2023

I think you have two problems here (that are basically the same problem). There's a few places where you're using index(fv!item, "index", "") where I think you should be just using fv!index. The difference is the latter is the index of a!forEach(), so you should generally use this index to keep track of your iterations within the a!forEach() instead of using your data. Here are the two issues:

On line 344, you aren't indexing the data correctly. You need to make sure that each iteration of the year range only returns the correct sum insured transactions. Something like this would probably work:

items: ri!sumInsTrans[wherecontains(
    fv!index, tointeger(index(ri!sumInsTrans, "index", null))
)],

The second issue is that you aren't adding the correct index when you add a new row. On line 452 I think you need to update this to also use fv!index.

In general some tips for troubleshooting - look for ways to display what data is being displayed within each iteration of the a!forEach(). I often do this by just displaying a text field that has the results of fv!item so I can easily tell what's being returned within each iteration. Also, if you have multiple a!forEach() functions nested within each other, I recommend using local variables to define each level so it's easy to keep track of the differences between each level.