Multi-row Variable Set - check for duplicates (or only accept unique values)

JLeong
Mega Sage

Hi Guys,

Need help on Multi-row Variable Set. I only have one column (single text), but I need to make sure that user doesn't enter the same value over and over. 

find_real_file.png

 

I am doing it on a Catalog Client script. Please assist.

Thank you in advance.

Regards,

Jocelyn

 

1 ACCEPTED SOLUTION

shouvik
ServiceNow Employee
ServiceNow Employee

This is OOB feature in Quebec. https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/product/service-catalog-management/concept/c_ServiceCatalogVariableSets.html

Variables  for a variable set has an attribute called Unique which does the validation automatically.

View solution in original post

18 REPLIES 18

@Shayon see my answer in this thread

https://community.servicenow.com/community?id=community_question&sys_id=8557faef1b8a5050305fea89bd4bcb73

Thanks Brad! I will try this too.

Hitoshi Ozawa
Giga Sage
Giga Sage

It's possible to check when entering MRVS rows by creating following script in MRVS (not on the form but in the MRVS). I've tested this on Paris.

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;
}

Hi Hozawa,

 

Yes I also had to check it on submit, could not find anyway to validate it whole adding an entry to the MVRS which would have been the ideal case, thanks for sharing the code, this would certainly help some out.

Thanks I will try this