Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to restrict duplicate values in MultiRow Variable set

suryamol_s
Kilo Guru

Hi All,

 

How to restrict duplicate entries in a multi row variable set. I am not able to fetch values from that.

 

Kindly help asap. 

Any help is appreciable.

 

Thanks & Regards,

Surya

10 REPLIES 10

i try to set form value to blank afer alert message,  and this also can satisfy my requirement, thanks.

Amit Verma
Kilo Patron
Kilo Patron

Hi @suryamol_s 

 

Please refer below post and configure an On-Submit Client Script to achieve this :

https://www.servicenow.com/community/developer-forum/how-to-stop-duplicates-entering-in-mrvs-based-o...

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Pooja58
Kilo Sage

Hi,

Below on Submit script works for me.

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var ast_id, len;

    ast_id = g_form.getValue('mrvs backend name');
    ast_id = JSON.parse(ast_id);
    len = ast_id.length;
    if (len > 1) {
        for (var i = 0; i < len; i++) {
            for (var j = i + 1; j < len; j++) {
                if (ast_id[i].display_name == ast_id[j].display_name) {
                    alert("Duplicate Entries. Please remove duplicates.");
                    return false;
                }
            }
        }
    }

}

 

 

You don't need a script anymore.

UncleRob_1-1733668873974.png

 

Uncle Rob
Kilo Patron

Saw this thread get resurrected and thought I'd add new information.
You no longer need to script to restrict duplicate values in an MRVS.
There's a property exposed on variables that are on MRVS called "Unique"
It ensures that whatever value you pick for that variable is unique among all the line items in the set.

UncleRob_0-1733668818378.png