- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 08:00 AM
Hi,
I am using an oChange client script to add or remove options to a choice list field.
The original choices have hints on attached them when you hover over them but if these options get removed and then added back using the g_form.addOption() method the hint does not come back with the option.
Is there a solution for this?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 09:12 AM
Okay. I don't see any OOB way to achieve this. The only way would be to do DOM manipulation which is not recommended. (and I am not good in DOM manipulation 😛 )
If your choice field is dependent on other field value then you can try dependent choice configuration.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 08:12 AM
Hello,
Can you share the script which you are using as it would be easier to correct it.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 08:32 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var state = g_form.getValue('state');
if (state == 7) {
g_form.removeOption('close_code','Closed/Resolved by Caller');
}
else if(state != 7){
g_form.addOption('close_code','Closed/Resolved by Caller','Closed/Resolved by Caller');
}
}
The issue is testHint disappears when I add the option back.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 08:32 AM
I'm not aware of any OOB functionality that would allow you to dynamically add a hint to the options you are adding via script. Which is not to say there is no way to do it, ServiceNow just does not give you a way to go about it OOB. So the only way I can see you doing this is to add the option then use g_form.getControl() to get the dropdown and from there you can add a title to the option.
So something like
var op = g_form.getControl("scalar_type");
op.options[0].title = "Flutty Rabbits";
I tested the above using the browser console so it should work in a client side script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2022 08:45 AM