g_form.removeOption is not working on the varialbe from a varialbe set

Francis Xavier
Tera Expert

Hi All,

I am trying to remove a specific  choice value from a variable.

The variable is used by multiple catalog items. So, we added a client script on a specific item to hide it.

But, the script is not hiding the choice value.

g_form.removeOption("loaner_selection",'visitor');

 

Kindly provide a quick solution to solve it 🙂

Thanks,

K. Francis Xavier

1 ACCEPTED SOLUTION

Francis Xavier
Tera Expert

This worked for me ::

 

Since each choice is unique you can hide them by using the document.getElementById in a onLoad catalog clients script. Just use your web inspector to find the right ID.

 

//Check the attachment to know how to get the IO ID.

https://community.servicenow.com/5bab600edbd09344e9737a9e0f961915.iix

var choice = document.getElementById("IO:2db72215876d11008eb5098e59434d8c_5c296215876d11008eb5098e59434df5").parentNode.parentNode;
if (choice){
choice.style.visibility="hidden";
choice.style.display="none";
}

View solution in original post

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Hi,

A quick solution is always nice, heh.

You can definitely get a quick solution if you speak to your peers at Accenture, since you're with a large partner firm...so a simple ping on your teams or slack social app I'm sure would get you help pretty quickly...

As far as removing an option from the variable, this will only work on a select-box type variable (not multiple choice). Please verify that you have the field name correct, as well as the value.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank you 🙂

Francis Xavier
Tera Expert

This worked for me ::

 

Since each choice is unique you can hide them by using the document.getElementById in a onLoad catalog clients script. Just use your web inspector to find the right ID.

 

//Check the attachment to know how to get the IO ID.

https://community.servicenow.com/5bab600edbd09344e9737a9e0f961915.iix

var choice = document.getElementById("IO:2db72215876d11008eb5098e59434d8c_5c296215876d11008eb5098e59434df5").parentNode.parentNode;
if (choice){
choice.style.visibility="hidden";
choice.style.display="none";
}

Paul Curwen
Giga Sage

Although the above advice will work, it's not great practice. Try this better approach. 

 

The reason you are seeing the issue is that g_form.removeOption does not work through Client Scripts that try to access a variable field on a task record. g_form is not a supported API for variables on Task Records

 

The way to get this working is using: g_sc_form.removeOption

 

e.g.

 

g_sc_form.removeOption('your_variable', 'your_value');

 

You can check the official advice on this at: 

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0678206

 

 

***If Correct/Helpful please take time mark as Correct/Helpful. It is much appreciated.***

Regards

Paul