Duplicate in the grid

Certified Associate Developer

Hi, 

I have a grid layout and the values are populated from my selection. I need to check, if there are duplicated values present in the grid. If there are duplicate values present, I should not able to submit the form. I store my selection in a local variable. 

validations: { 

if(

local!data.value ---> here I need to check if the value is already present in the grid. 

"pleaser remove duplicates",

""

)

}

Can someone please help how to check if the values are already present.  

  Discussion posts and replies are publicly visible

Parents Reply
  • +1
    Certified Lead Developer
    in reply to hema.mathivathanan

    You can add a validation item on your grid, which checks whether there are duplicate values within that column.  I wrote a rule a while ago which looks into an array and returns any items that are duplicated within the array any number of times, which I'll share below.

    For the validation message on your grid:

    a!validationMessage(
      message: "Duplicate Amounts are present.",
      validateAfter: "SUBMIT",
      showWhen: length(
        rule!GLBL_getArrayDuplicates(local!gridData.Amount)
      ) > 0
    )

    For the rule GLBL_getArrayDuplicates():

    a!flatten(
      a!forEach(
        ri!array,
        if(
          length(wherecontains(
            fv!item,
            cast(typeof({fv!item}), ri!array)  /* (this allows us to handle a mixed-type array properly) */
          )) > 1,
          fv!item,
          {}
        )
      )
    )

Children
No Data