Answered

how to validate unique Id's in an Array

Hi,

does anyone know how to create a unique id validation in an array?

i managed with the following:

if(!this.value) {
  return true;
}

return this.root.personalDetails.idNumber.value != this.value;

 

but it only keeps the user from repeating the main id from the items. but how do i prevent the user from using the same id in other items in the same array?

 

1

Didn't find what you were looking for?

New post

Comments

4 comments

  • Official comment

    Hi Erez! I have a different solution suggestion for you. Instead of coding a new validation use the formula editor. Check out the process and the formula.

    https://dx-onboarding-dev.easysend.app/ku48yqcm33qaubwo3ugf/page0/0?lang=en&rid=NJLOClZBpO0

    IF(COUNT_UNIQUE($displayArray.array[*].id) < ARRAY_LENGTH($displayArray.array[*].id),true,false)
     
    The formula counts all the unique values in the array. If the size of the array is bigger than the count it indicates that there is a duplication. When the formula returns true an error message appears (rich text inside a container) and the button to move to the next page is disabled until the duplication is corrected.
     
    Let me know if you have any questions.
     
    Thank you!  
  • Hi Roony,

    tnx for the answer! 

    it seems this formula address the issue within the array itself

    does it take in consideration the main id outside of the array?

     

    0
  • Hi Erez! Please see the modifications to the formula. 

    IF(COUNT_UNIQUE($displayArray.array[*].id) < ARRAY_LENGTH($displayArray.array[*].id) or LOOKUP("=", $main, $displayArray.array[*].id,$displayArray.array[*].id) = $main,true)
    Check it out
     
    As an added bonus, extra free of charge, the formula also checks the the main ID was not left empty :)
     
    Thank you!
    1
  • 0

Please sign in to leave a comment.