User should not be able to select same user two times in Multi-row variable set.

Brijmohan
Tera Contributor

I am stuck on one requirement. There is one Multi-row variable set in catalog item where requester can add up to 100 users but should not be able to add the same User twice".

How I can restrict this? Please suggest.

Thanks in advance!

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello , 

For avoiding duplicate entries you can create an on submit client script inside MVRS 

PLease use the below script this will work for sure

function onSubmit() {
    var value = parent.g_form.getValue("<mrvs name>"); // change mrvs name
    var arr = JSON.parse(value);

    if (searchExisting(g_form.getValue("<column name to check>"), arr)) { // change column name
       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].<column name to check> == keyColumn) {  // change column name
            return true;
        }
    }
    return false;
}

Please accept the solution if it helped you and close the thread. This might help others too with same query

Thanks

View solution in original post

9 REPLIES 9

Mohith Devatte
Tera Sage
Tera Sage

Hello , 

For avoiding duplicate entries you can create an on submit client script inside MVRS 

PLease use the below script this will work for sure

function onSubmit() {
    var value = parent.g_form.getValue("<mrvs name>"); // change mrvs name
    var arr = JSON.parse(value);

    if (searchExisting(g_form.getValue("<column name to check>"), arr)) { // change column name
       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].<column name to check> == keyColumn) {  // change column name
            return true;
        }
    }
    return false;
}

Please accept the solution if it helped you and close the thread. This might help others too with same query

Thanks

It worked, Thank you Mohith for quick solution.

Hi Mohith,

There is one issue that i found. When i am doing this on catalog form via try it, it is working as expected but when i am selecting the user info via service portal it is not working. We can select same user twice. 

Also I am getting "There is a JavaScript error in your browser console" on service portal. 

Could you please help on this ?

Hello,

usually this happens when  there is some thing wrong with the script that we write in catalog client script

Please try these below debugging steps

In your  client script check if   you selected "Type"  as desktop or All.

If  you have selected desktop please change it to ALL and try.

please mark this helpful if it solves your issue