Appian Community and Appian Academy are being upgraded. As a part of the upgrade, Appian Community is currently in read-only mode, and user registration is disabled until August 3. We apologize for any inconvenience this may cause, but a more secure, stable, and performant Community experience is coming soon!

The new Appian Community launches August 3, followed by Appian Academy on August 7. During the migration, Appian Community Edition, Appian Academy, Documentation, Certifications, Instructor-led Customer Training, Partner Sales Training & Accreditation, and Forum (for Appian Partners and Customers only) will remain available.

Editable grid validation

Certified Senior Developer

I have to validate a editable grid  for the following scenario -

          I have two fields in the grid 1. Role 2. Location

use case - if the user select combination of same role and location as a duplicate then it should thrown an validation error like combination of role and location already exits.

example - if the user select role as developer and location as india and again he adding a new row and selecting the same role and same location it should throw an error   

any one suggest some idea

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Please try this.

    a!localVariables(
      local!data,
      a!gridLayout(
        headerCells: {
          a!gridLayoutHeaderCell(label: "Role"),
          a!gridLayoutHeaderCell(label: "Location")
        },
        addRowLink: a!dynamicLink(
          label: "Add",
          saveInto: {
            a!save(
              local!data,
              append(local!data, { role: "", loc: "" })
            )
          }
        ),
        rows: a!forEach(
          items: local!data,
          expression: a!gridRowLayout(
            contents: {
              a!dropdownField(
                choiceLabels: { "Dev", "Tester" },
                choiceValues: { "Dev", "Tester" },
                placeholder: "---",
                value: fv!item.role,
                saveInto: fv!item.role,
                validations: if(
                  count(
                    intersection(
                      wherecontains(
                        tostring(fv!item.role),
                        a!flatten(local!data.role)
                      ),
                      wherecontains(
                        tostring(fv!item.loc),
                        a!flatten(local!data.loc)
                      )
                    )
                  ) > 1,
                  "combination of role and location already exits",
                  ""
                )
              ),
              a!dropdownField(
                choiceLabels: { "India", "USA", "AUS" },
                choiceValues: { "India", "USA", "AUS" },
                placeholder: "---",
                value: fv!item.loc,
                saveInto: fv!item.loc,
                validations: if(
                  count(
                    intersection(
                      wherecontains(
                        tostring(fv!item.role),
                        a!flatten(local!data.role)
                      ),
                      wherecontains(
                        tostring(fv!item.loc),
                        a!flatten(local!data.loc)
                      )
                    )
                  ) > 1,
                  "combination of role and location already exits",
                  ""
                )
              )
            }
          )
        )
      )
    )

  • You can add the below piece of code as validation on both the dropdowns - Role and location.

    if(
      and(
        or(
          count(
            wherecontains(fv!item.role, local!array.role)
          ) > 1,
          count(
            wherecontains(fv!item.Location, local!array.Location)
          ) > 1
        ),
        wherecontains(fv!item.role, local!array.role) = wherecontains(fv!item.Location, local!array.Location)
      ),
      "Combination of role and location should be unique.",
      {}
    )
     

  • 0
    Certified Lead Developer

    I have much easier way.

    a!localVariables(
      local!array: { { role: null, Location: null } },
      a!gridLayout(
        headerCells: {
          a!gridLayoutHeaderCell(label: "Role"),
          a!gridLayoutHeaderCell(label: "Location")
        },
        rows: a!forEach(
          items: local!array,
          expression: a!gridRowLayout(
            contents: {
              a!dropdownFieldByIndex(
                choiceLabels: { "Abc", "Def", "Ghi" },
                validations: if(
                  count(wherecontains(fv!item, local!array)) > 1,
                  "Combination of role and location should be unique.",
                  {}
                ),
                value: fv!item.role,
                saveInto: local!array[fv!index].role,
                placeholder: "-"
              ),
              a!dropdownFieldByIndex(
                choiceLabels: { "L1", "L2", "L3" },
                validations: if(
                  count(wherecontains(fv!item, local!array)) > 1,
                  "Combination of role and location should be unique.",
                  {}
                ),
                value: fv!item.Location,
                saveInto: local!array[fv!index].Location,
                placeholder: "-"
              )
            }
          )
        ),
        addRowLink: a!dynamicLink(
          label: "Add",
          value: append(local!array, { role: null, Location: null }),
          saveInto: local!array
        ),
        
      )
    )

  • 0
    Certified Lead Developer
    in reply to ujjwalr0002

    Oh yes. We do not need multiple whereContains(). Nice catch Ujjwal!