Check Duplicate Value Selected in Multi-Row Variable Set

Radek Homola
Kilo Expert

Hello, community,

I have Multi-Row Variable Set and I need to check if one of the values has been already selected onChange of the value inside the MVRS. I'm trying to use Catalog Client Script for that – but firstly – I'm facing the issue that I cannot reach the already inserted values using g_form to compare it with newValue.

Does somebody know how to get to that values?

 

Thanks

1 ACCEPTED SOLUTION

Radek Homola
Kilo Expert

I solved it by myself – but I'd like to share the solution with you.

 

1. Create a Catalog Client Script related to the Catalog Item with this content (onLoad):

//save rows from MRVS into some global variable
GLOBAL_VAR = {g_form: g_form}

 

2. Create another Catalog Client Script related to a variable set which takes the data from the global variable (onChange):

//take the rows from global variable
var data = GLOBAL_VAR.g_form.getValue("mrvs_name");

//parse it!
var object = JSON.parse(data);

 

Now you can easily access to the data in MVRS and compare it.

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

See this article for some things I've been able to do with MRVS scripting.  Part of this sounds like what you might be trying to do.

https://community.servicenow.com/community?id=community_article&sys_id=5ebe74c0db2f00905129a851ca961...

Radek Homola
Kilo Expert

I solved it by myself – but I'd like to share the solution with you.

 

1. Create a Catalog Client Script related to the Catalog Item with this content (onLoad):

//save rows from MRVS into some global variable
GLOBAL_VAR = {g_form: g_form}

 

2. Create another Catalog Client Script related to a variable set which takes the data from the global variable (onChange):

//take the rows from global variable
var data = GLOBAL_VAR.g_form.getValue("mrvs_name");

//parse it!
var object = JSON.parse(data);

 

Now you can easily access to the data in MVRS and compare it.

Can you please show it by some examples if possible.

Like with some dummy variables etc

Hitoshi Ozawa
Giga Sage
Giga Sage

Even though this question has already been answered, another way to prevent duplicate entries in multi-row variable set is to create a script in multi-row variable set instead of in the form's catalog client script. This has an additional advantage of being able to detect duplicate when the user tried to add the row in the multi-row variable set instead of having to wait until the user submits the form.

Further information available in the thread below.

https://community.servicenow.com/community?id=community_question&sys_id=1914e50fdb7a1c14a08a1ea66896...