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 Children
  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    In the grid, for a particular field I select values from another table. The selected value appears in the grid. 
    Now, I am able to select the same value twice. But, it should not happen.

    For example, if I have the same value twice, it should throw the error, "duplicate values are present". please check

  • 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,
          {}
        )
      )
    )