Why Remove Option or AddOption is not working for catalog item?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 12:56 AM
Hi Team,
I am trying to add and remove option for region field but its not working
Trying this for catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 01:24 AM
Please comment line 4 from your code and modify line 6,7 as below.
function onLoad() {
//Type appropriate comment here, and begin script below
// 'Show "All India, Central" this two options in region variable for Selection'
if(g_form.getValue("region") == ''){
g_form.removeOption("region","All Region");
}
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 01:26 AM
if(g_form.getValue("region")== null) remove null by empty space this will not working because of null.use this if(g_form.getValue("region")== ' ')
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 02:21 AM
Hello @Prathamesh Chav
- Try this updated client script:
function onLoad() {
if (!g_form.getValue("region")) {
// 'Show "All India, Central" this two options in region variable for Selection'
g_form.removeOption("region", "All Region");
}
}
- Syntax for g_form.removeOption() method:
g_form.removeOption(fieldName, optionValue);
- Comments should always start with //
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar