- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2021 07:10 PM
Hi expert!
I am trying to remove a choice from a catalog item variable.
I have written a client script to remove the choices with the following conditions, but it does not work.
●Variable
Question |
VAR_A |
Name | t015 |
●Question choises
Text | test1(remove it) | test2 |
Value | 1 | 2 |
●Client Script
function onLoad() {
g_form.removeOption('t015','1');
}
However, as shown in the image below, "test" is displayed.
How can I help you?
Best regard.
senon.
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2021 07:41 PM
Few things to check
1) UI Type - ALL
2) Are you using correct variable name and correct choice value
Can you try this script
function onLoad() {
g_form.removeOption('t015',1);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2021 07:45 PM
Hi,
In the script shown above, I don't see any specific condition on which you want to removed the choice option name "test1", so I will suggest in that case navigate to the choic list option for that field and simply mark the option as "Inactive = True" which will solve the issue and you dont't need a script for this.
Still if you want to go with the help of scripts then few things to take care of like for example if this particular field is getting values from another field based on dependent concept, you need to look around that or another way to handle this might be clear all the options and then just add the option you want like for example the code mentioned below:
function onLoad() {
g_form.clearOptions('t015');
g_form.addOption('t015','1','Choice Label');
}
Hope this helps. Please mark the answer as helpful/correct based on impact.
Regards,
Shloke
Regards,
Shloke