Preventing duplicates in MRVS

Vengadesh
Tera Guru

Hi , Im facing issues in the below onsubmit  catalog client script .It loops multiples times and I'm getting the same alert "alert("No duplicates found");" even if I dont have any duplicates 

Here is the code :

var gr = g_form.getValue("u_duplicate");

    var parsedValue = JSON.parse(gr);

    var arr = [];

    for (var i = 0; i < parsedValue.length; i++) {

        var value = parsedValue[i].u_application;

        if (arr.includes(value)) {

            alert("Duplicate entry found: " + value);

            return false; // Prevent form submission

        } else {

            arr.push(value);

        }

    }

    alert("No duplicates found");

    return true;

1 REPLY 1

Vaishnavi Lathk
Mega Sage
Mega Sage

 

function onSubmit() {
var value = parent.g_form.getValue("u_duplicate"); // change mrvs name
var arr = JSON.parse(value);
if (searchExisting(g_form.getValue("u_duplicate"), arr)) {
alert('There are duplicates please remove those before submitting');
return false;
}
}

function searchExisting(keyColumn, newArray) {
for (var i = 0; i < newArray.length; i++) {
if (newArray[i].u_duplicate == keyColumn) {
return true;
}
}
return false;
}