Finding Duplicate Values
On a form, I had 3 keyword fields where the choices were all identical. I wanted to make sure that no value was picked in multiple fields. (There could be omitted values between the 3 fields, but no duplicates were allowed). At first, I thought a simple @Replace would do the trick, but that replaced ALL instances, so even if a value was listed twice it would be replaced both times and not be reported as a duplicate. Here's the code I came up with:AllSelectedOptions := KeywordField1 : KeywordField2 : KeywordField3;
TempList := "";
DuplicatedValues := "";
ScanForDuplicates := @For(i := 1; i <= @Elements(AllSelectedOptions); i := i+1;
x := @Subset(@Subset(AllSelectedOptions; i); -1);
@If(@IsMember(x; TempList); DuplicatedValues := @Trim(DuplicatedValues : x); TempList := @Trim(TempList : x))
);
At this point in the formula, the variable DuplicatedValues has a list of all the values that were listed in more than 1 of the keyword fields. Note that I didn't show the rest of the code since it wasn't really relevant. You can check for the number of elements in DuplicatedValues and give a prompt box (@Failure) or use this in computed text to show the duplicates (like I did).
The way the code actually works is that the 3 keyword lists are combined together. Then the code loops through each individual value. If the value is already in the temporary list, it's a duplicate and it's added to the DuplicatedValues variable. If the value isn't already in the temporary list, then it's added to the temporary list for future consideration.