How to hide selected dropdown choice in multi row variable set

nitin51
Tera Contributor

how to hide already selected dropdown choice in multi row variable set (for next row add - the already selected choice should not display in choices). 

 

I have an mrvs and in that one variable (addtest) of dropdown with some choices test1, test2, test3. If I select test1 in first row add and I want to add next row in the available dropdown choices test2 and test3 should be available. 

1 ACCEPTED SOLUTION

Appanna M
Tera Guru

Hello Nitin,

 

Try this below OnLoad script inside your variable set. Make it helpful if its solve your issue. 

 

function onLoad() {
try {
//Type appropriate comment here, and begin script below
var mrvsValues = parent.g_form.getValue('your_mrvs_variable_name');
var obj = JSON.parse(mrvsValues);
for (var i = 0; i < obj.length; i++) {
g_form.removeOption('your_variable, obj[i].your_variable);

}
} catch (err) {
alert("Error:" + err);
}
}

View solution in original post

4 REPLIES 4

Tbskllr
Tera Expert

Hi, you can create an onLoad Catalog Client Script for this - remember to change the names in lines 2 and 8:

function onLoad() {
  var multiRowValues = g_service_catalog.parent.getValue('technical_name_of_your_mrvs'); // change variable set name here

  if (multiRowValues && multiRowValues.length > 2) {
    var obj = JSON.parse(multiRowValues);

    obj.forEach(function(option) {
      g_form.removeOption('your_variable', option.your_variable); // change variable name here
    });
  }
}

 

Check out the documentation on g_serverice_catalog here: https://developer.servicenow.com/dev.do#!/reference/api/utah/client/g_service_catalogClientAPI

Thanks for the script. But an error is coming if we select the edit row option. The values changes

Hi Arpita,

 

Can you paste the error message along with example of your usecase here?

 

Regards,

Appanna.

Appanna M
Tera Guru

Hello Nitin,

 

Try this below OnLoad script inside your variable set. Make it helpful if its solve your issue. 

 

function onLoad() {
try {
//Type appropriate comment here, and begin script below
var mrvsValues = parent.g_form.getValue('your_mrvs_variable_name');
var obj = JSON.parse(mrvsValues);
for (var i = 0; i < obj.length; i++) {
g_form.removeOption('your_variable, obj[i].your_variable);

}
} catch (err) {
alert("Error:" + err);
}
}