Add hints to choices via script

Jake Sadler
Kilo Sage

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?

1 ACCEPTED SOLUTION

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.

 

https://docs.servicenow.com/bundle/sandiego-platform-administration/page/administer/field-administra...

https://community.servicenow.com/community?id=community_question&sys_id=2e05b490db214510f77799ead396...

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

9 REPLIES 9

Saurav11
Kilo Patron
Kilo Patron

Hello,

Can you share the script which you are using as it would be easier to correct it.

Thanks

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.

 

find_real_file.png

DrewW
Mega Sage
Mega Sage

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.

 

Hi,

 

Do you know how I would use this to add a hint to a choice list option?

 

find_real_file.png