Getting few bugs in the code

I've few questions to ask, those might be trivial issues but important.

1. I have set a grid level validation in an inline dynamic editable grid. Every time user generates a new row with add row link and tries to submit the form without filling any field, it shows up validation message. But it is showing for multiple times, i.e. times the number of rows generated. I want it to be like validation binds every unfilled field or row but should appear only once. Below is the screenshot of issue. Here it's appearing 3 times for 3 rows, I want it shows validation error message only once for all three rows.

2. Second issue is related to the first one, when user for example, first deletes any of the row using "X" and then again generates the new row back using add row link, validation message automatically appears for that, which shouldn't be the case. Below captured video shows the issue.

 

3. Getting a strange error:

Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!gridLayout [line 6]: Rule 'l' has 1 parameters, but instead passed 0 parameters.

I am not using any "I" named rule, pls check the whole code below:

4.. I think, I might have addressed this one in my previous queries. 

I have a dropdown with name "Request Type" having two choices "Supply" and "Service", and there is one "Item" textfield in which Item Name needs to be entered. When user selects a "Service", then "Item" value should be stored in "Service Type" table and for "Supply" in "Supply Type" table, which is occurring with the code I have written, but the issue is "If user suppose in between changes the "Request Type" from "Service" to "Supply", then "Item" value stored in "Service Type" CDT should return back to null state and newly entered "Item" value should store in "Supply Type" CDT, which is not coming up and it's retaining both Item values in both CDTs, i.e Ex- He entered "PC" for "Supply" but then changed it's "Request Type" to "Service" and entered Item as "S/w Installation", then as a result "Supply Type" CDT has Item value "PC", and with that "Service Type" CDT has Item value "S/w Installation", which shouldn't be the case i.e. Item value "PC" in "Supply Type" CDT should default back to null.

I have highlighted the code in comments:

a!localVariables(
  a!formLayout(
    label: "Create New Request",
    instructions: "Create a new Request Type|Maximum 5 requests can be created at a time",
    contents: {
      a!gridLayout(
        totalCount: count(
          ri!requestTypeRef
        ),
        headerCells: {
          a!gridLayoutHeaderCell(
            label: "Request Type*"
          ),
          a!gridLayoutHeaderCell(
            label: "Item*"
          ),
          a!gridLayoutHeaderCell(
            label: "Quantity*"
          ),
          a!gridLayoutHeaderCell(
            label: "Price ($)*"
          ),
          a!gridLayoutHeaderCell(
            label: "Comment*",
            align: "RIGHT"
          ),
          a!gridLayoutHeaderCell(
            label: ""
          )
        },
        columnConfigs: {
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 2
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 2
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 1
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 1
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 2
          ),
          a!gridLayoutColumnConfig(
            width: "ICON"
          )
        },
        rows: a!forEach(
          items: ri!requestTypeRef,
          expression: a!gridRowLayout(
            id: fv!index,
            contents: {
            
            
             /* a!dropdownField(
                label: "request type " & fv!index,
                placeholderLabel: "---Please select value---",
                choiceLabels: cons!OSR_TEXT_ARRAY_REQUEST_TYPE,
                choiceValues: cons!OSR_TEXT_ARRAY_REQUEST_TYPE,
                value: index(fv!item, "RequestTypeName", {}),
                saveInto: fv!item.RequestTypeName,
                required: true
              ),
              a!textField(
                label: "item " & fv!index,
                value: if(
                  ri!requestTypeRef[fv!index].RequestTypeName = "Service",
                  index(
                    ri!serviceTypeRef[fv!index],
                    "ServiceTypeName",
                    {}
                  ),
                  index(
                    ri!supplyTypeRef[fv!index],
                    "SupplyTypeName",
                    {}
                  )
                ),
                saveInto: if(
                  ri!requestTypeRef[fv!index].RequestTypeName = "Service",
                  ri!serviceTypeRef[fv!index].ServiceTypeName,
                  ri!supplyTypeRef[fv!index].SupplyTypeName
                ),
                required: true
              ),*/
              
              
              
              a!integerField(
                label: "quantity " & fv!index,
                value: index(
                  ri!request[fv!index],
                  "Quantity",
                  {}
                ),
                saveInto: ri!request[fv!index].Quantity,
                required: true
              ),
              a!floatingPointField(
                label: "price " & fv!index,
                value: todecimal(
                  index(
                    ri!request[fv!index],
                    "Price",
                    {}
                  )
                ),
                saveInto: ri!request[fv!index].Price,
                required: true
              ),
              a!paragraphField(
                label: "comment " & fv!index,
                value: index(
                  ri!comment[fv!index],
                  "Comment",
                  {}
                ),
                saveInto: ri!comment[fv!index].Comment,
                required: true
              ),
              a!imageField(
                label: "delete " & fv!index,
                images: a!documentImage(
                  document: a!iconIndicator(
                    "REMOVE"
                  ),
                  altText: "Remove Request",
                  caption: "Remove ",
                  link: a!dynamicLink(
                    value: fv!index,
                    saveInto: {
                      a!save(
                        ri!request,
                        remove(
                          ri!request,
                          save!value
                        )
                      ),
                      a!save(
                        ri!requestTypeRef,
                        remove(
                          ri!requestTypeRef,
                          save!value
                        )
                      ),
                      a!save(
                        ri!serviceTypeRef,
                        remove(
                          ri!serviceTypeRef,
                          save!value
                        )
                      ),
                      a!save(
                        ri!supplyTypeRef,
                        remove(
                          ri!supplyTypeRef,
                          save!value
                        )
                      ),
                      a!save(
                        ri!comment,
                        remove(
                          ri!comment,
                          save!value
                        )
                      )
                    }
                  )
                ),
                size: "ICON"
              )
            }
          )
        ),
        addRowlink: a!dynamicLink(
          label: "Add New Request",
          value: null,
          showWhen: count(
            ri!requestTypeRef
          ) < 5,
          saveInto: {
            a!save(
              ri!request,
              append(
                ri!request,
                save!value
              )
            ),
            a!save(
              ri!requestTypeRef,
              append(
                ri!requestTypeRef,
                save!value
              )
            ),
            a!save(
              ri!serviceTypeRef,
              append(
                ri!serviceTypeRef,
                save!value
              )
            ),
            a!save(
              ri!supplyTypeRef,
              append(
                ri!supplyTypeRef,
                save!value
              )
            ),
            a!save(
              ri!comment,
              append(
                ri!comment,
                save!value
              )
            )
          }
        ),
        rowHeader: 1,
        validations: {
          a!forEach(
            items: ri!requestTypeRef,
            expression: if(
              or(
                isnull(
                  ri!requestTypeRef[fv!index].RequestTypeName
                ),
                isnull(
                  ri!request[fv!index].Quantity
                ),
                isnull(
                  ri!request[fv!index].Price
                ),
                isnull(
                  ri!comment[fv!index].Comment
                )
              ),
              a!validationMessage(
                message: "Please fill all the Required* fields!",
                validateAfter: "SUBMIT"
              ),
              {}
            )
          )
        }
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: cons!OSR_TEXT_BUTTON_SUBMIT,
          submit: true,
          style: "PRIMARY"
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: cons!OSR_TEXT_BUTTON_CANCEL,
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "NORMAL"
        )
      }
    )
  )
)

Thanks a lot in advance.

 Discussion posts and replies are publicly visible