- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2023 10:50 PM
Hi,
Need your help to remove(hide) the values starts with SNOW from the category drop down list into SP. The below script is working correctly but i should remove dynamically instead of calling removeoption for each category. If a new value(starts with SNOW) category is added in future, this code should remove it automatically from the particular record producer.
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.removeOption('category', 'SNOW-Modules');
g_form.removeOption('category', 'SNOW-Compensation');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2023 01:42 AM
Instead of going with catalog client, can you try using reference qualifier to not show options starting with SNOW.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 07:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 07:30 AM
You can try this script with Onload also.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var selectBox = g_form.getControl('your_dropdown_field');
for (var i = 0; i < selectBox.options.length; i++) {
if (selectBox.options[i].text.startsWith('SNOW')) {
selectBox.remove(i);
}
}
}
Please mark it Correct and Hit Like if you find this helpful!
Regards,
Karthiga

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 11:56 AM
Hello @BanuMahalakshmi
If you put all categories like this, obviously it wouldn't be scalable.
- One way to achieve this is to use a client script that loops through the options and removes the ones that match a certain condition. Try this below code.
function onLoad() {
//Get the choice list element
var category = g_form.getControl(‘category’);
//Loop through the options
for (var i = 0; i < category.options.length; i++) {
//Get the option value
var option = category.options[i].value;
//Check if it starts with SNOW
if (option.startsWith(‘SNOW’)) {
//Remove the option
g_form.removeOption(‘category’, option);
}
}
}
- Another way to achieve this is to use a UI policy that sets the available choices for the category field based on a condition.
- Condition: true (always apply)
- Script: true (use script to set choices)
- Script:
//Get the choice list element
var category = g_form.getControl(‘category’);
//Create an array of choices to keep
var choices = [];
//Loop through the options
for (var i = 0; i < category.options.length; i++) {
//Get the option value
var option = category.options[i].value;
//Check if it does not start with SNOW
if (!option.startsWith(‘SNOW’)) {
//Add the option to the array
choices.push(option);
}
}
//Set the available choices for the category field
g_form.setAvailableChoices(‘category’, choices);
Hope this helps
Kind Regards,
Swarnadeep Nandy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 10:09 PM
Hi @BanuMahalakshmi ,
you can try below onchange client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue.indexOf("SNOW")==0){//choice should starts with snow
g_form.removeOption('category',newValue);
}
}
or on submit
function onSubmit() {
var val=g_form.getValue('category');
if(val.indexOf("SNOW")==0){
return false;
}
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 11:40 PM
Hi Thanks for reply, The newValue can get only one value from the category drop down list but i want to check all the drop down values. Also the script g_form.getValue('category') also fetching only one value but not all the values from the category drop down list.