Skip to main content
March 17, 2022
Question

Checking for duplicates in an array or list

  • March 17, 2022
  • 20 replies
  • 2 views

Hi

I want to check for duplicates in Supplier list when I am adding a new supplier. 

I tried using this expresssion:

 

a!textField(
                label: "Supplier Name",
                value: fv!item.description,
                saveInto: fv!item.description,
                validations:
                {
                  if(
                    count(wherecontains(local!suppliers,index(fv!item,fv!index,{})))>1,
                    "Supplier already exists",{}
)
},

But I am getting the error -> Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!forEach [line 39]: Error in a!forEach() expression during iteration 1: Expression evaluation error at function 'wherecontains' [line 52]: Invalid types, can only act on data of the same type (Any Type, Text)

I tried the methods mentioned in earlier posts but not able to fix it yet. Can someone help me?

Thanks

    20 replies

    danny.verb
    March 17, 2022

    You need to wrap 'local!suppliers' in the function touniformstring() which will make sure that you're acting on data of the same type

    March 17, 2022

    Hi Danny,

    Thanks for the tip but I tried it earlier and it didn't work. 

    I am getting the same error

     rows: a!forEach(
              items: local!suppliers,
              expression: a!gridRowLayout(
                contents: {
                  a!textField(
                    label: "Supplier Name",
                    value: fv!item.description,
                    saveInto: fv!item.description,
                    validations:
                    {
                      if(
                        count(wherecontains(touniformstring(local!suppliers),index(fv!item,fv!index,{})))>1,
                        "Supplier already exists",{}
                      )
                    },
                   

    Thanks

    gopalk2865
    Participating Frequently
    March 17, 2022

    Hi, first thing you need to use touniformstring () as Danny said ,to make sure you are working on same type of data. Apart from this why are you indexing fv!index from fv!items? I think you need to correct this too.

    March 17, 2022

    Hi Gopal,

    I am trying the check for duplicates. 

    Should I use the column name directly instead of fv!index?

    Thanks

    gopalk2865
    Participating Frequently
    March 17, 2022

    If you are storing supplier name in fv!item.description then you should use this field only to check whether value provided by user exists in local! suppliers or not.i assume you have list of suppliers in local!suppliers then your expression should be like below,

    WhereContains(touniformstring (local! suppliers),fv!item.description)