Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

How do I check for duplicate Employee Names throughout a form with multiple repeating tables?

nowackem
Level 4
Level 4

Good Afternoon,

@PulkitJain this is the form you just helped me with. I'm hoping you or someone can help me as this request is a little more complicated. I need to run a script that will check for duplicates within the employeeName field but this table has a repeating row AND the entire table is running an add and instance script. A pop up window will work or even highlighting the duplicated names would work.

Please see the form here: 

https://drive.google.com/file/d/1oVWCDknyCNWwImMSOHKK0990-1O7ITzB/view?usp=sharing

Thank you,

Emilee

 

1 Accepted Solution
Mayank_Tiwari
Correct answer by
Employee
Employee

I got it working. Please see below and confirm that's what you wanted. Duplicates are highlighted in all the tables on button click.

 

Mayank_Tiwari_0-1635452810957.png

Update Form: https://drive.google.com/file/d/1RQhNjPKf28AjUuNbPmnv73ZrZU-N-8jq/view?usp=sharing

View solution in original post

10 Replies
PulkitJain
Employee
Employee

@nowackem 

I see that there could be multiple rows/employee names in a table and multiple tables (with "Add payroll information")

What event do you want to check the duplicate values with? I don't see any submit button or option to save the form. We can check for the duplicate names but wanted to understand the use-case better.

 

 

nowackem
Level 4
Level 4

@PulkitJain The idea is that the users/customers would submit the form but the user wouldnt really be the ones looking at the duplicates, it would be our employees who would look for duplicates. If we had to create a button for our people to click to find them easily that would work. What do you suggest?

Mayank_Tiwari
Employee
Employee

I have fixed your form with the script below, being executed on employeeName column's Exit event. Please check it out!

 

 

var rows = this.resolveNodes("tbleEmployeeInfo.repeatingRow[*]");
var dup = false;
for (var i = 0; i < rows.length; i++) {

    for (var j = 0; j < rows.length; j++) {
        if (i != j) {
            if (rows.item(i).employeeName.rawValue == rows.item(j).employeeName.rawValue) {

                dup = true;
                break;
            }
        }
    }
}
if(dup)
xfa.host.messageBox("Duplicate Found");

Fixed form: https://drive.google.com/file/d/1RQhNjPKf28AjUuNbPmnv73ZrZU-N-8jq/view?usp=sharing

 

 

nowackem
Level 4
Level 4

This seems to check only within a table, I would need to have it check the whole form once it is filled out. The other thing is that it doesnt need to happen while filling out as duplicates are ok and I dont want to alarm our customers. Our employees take that filled out form and search for the duplicates and might need to make an adjustment. The way this is, it seems like it creates an error window only within the one table at a time. Maybe a button really is the better way to go? I will spend more time tomorrow. Sorry I work for the state and cant stay later. 🙂 Thank you so much for your time. 🙂 Have a good night!

Mayank_Tiwari
Employee
Employee

You may add a Validate button on the form, and add the same script on the click event of the button for all the tables in the form. The logic would be same. 

nowackem
Level 4
Level 4

@Mayank_Tiwari I was able to create a validate button at the bottom of the form and get it to work the same as your original idea. The issue is that it still only indicates duplicates within the original table. For example, if I put a value in the first employeeName field then click on the "Add Payroll Information" button then put the same value in the new employeeName field, it does not catch duplicates in both tables this script (the way I have it) only works on the very first table. Is there a way to check for duplicates for infinity add instances of subPayRollInfo? Also, now that I've seen this run I realized that just indicating there is a duplicate will not really help as we will still have to hunt for them(this form could get lengthy). Can we highlight all the duplicates instead? Is that possible? 

https://drive.google.com/drive/folders/1gNJSIUYdh-i-sR07mlwzOsl1Fv2jp-s4?usp=sharing

 

Mayank_Tiwari
Employee
Employee

You need to merge the repeatingRow array from each of the subPayRollInfo instance into a single array, by using a loop. And then apply the same logic on the merged array to find the duplicates. 

nowackem
Level 4
Level 4

Please forgive me, I just cant get this to work. Can you look at my document and see where I'm going wrong? I need to specify where the duplicates are and highlight them somehow when the button is clicked. I've tried a few things but I still cant get the script to check any table but the first one. Thank you again for your help.

Mayank_Tiwari
Correct answer by
Employee
Employee

I got it working. Please see below and confirm that's what you wanted. Duplicates are highlighted in all the tables on button click.

 

Mayank_Tiwari_0-1635452810957.png

Update Form: https://drive.google.com/file/d/1RQhNjPKf28AjUuNbPmnv73ZrZU-N-8jq/view?usp=sharing

View solution in original post

nowackem
Level 4
Level 4

Thats it! I thank you from the bottom of my heart!!! I'm learning everyday and you guys are a big part of it.