- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2015 11:38 PM
Hi,
Apart from classic way using client script g_form.removeOption('') and g_form.addOption(''), is there any best practice add and remove options in Choice List?
Thanks
Iyyappan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2015 11:58 PM
Hi Iyyappan,
Although as the whole thread says...addOption, clearOptions and removeOption are the best way to go and i totally agree to that. As far as performance is concerned these functions don't have any noticeable impact. These are service now methods to browser dependency and upgrade support is also there OOB.
Still if you want another option.. here is a code by Harish Murikinati ...This code doesn't remove the option but disable it, options will be there but user wont be able to select them.
disableOption();
function disableOption()
{
var fieldName = 'u_status';
var control = g_form.getControl(fieldName);
if (control && !control.options)
{
var name = 'sys_select.' + this.tableName + '.' + fieldName;
control = gel(name);
}
if (!control)
return;
if (!control.options)
return;
var options = control.options;
for (var i = 1; i < options.length; i++)
{
var option = options[i];
alert('hello'+ options[i].value);
if(g_user.hasRole('itil') && (options[i].value == "Draft" || options[i].value == 'Review' || options[i].value == 'Closed'))
{
control.options[i].disabled = 'true';
}
}
}
Check this thread for more information
Lock down change states for users with change_management role
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2015 04:07 AM
I have used this alternative as posted on snguru in the past:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2015 04:13 AM
Best practice from service now says that we should use the functions provided by them .. Hence g_form.removeOption('') and g_form.addOption('').
Are you looking for something else ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2015 08:10 AM
what are you trying to accomplish and where would be my questions.. add/remove options work great as long as they are run in an onload script.. that way they only run once each...
removes work fine in an onchange script.. but add/s in an onchange script can result in you having the same choice multiple times... so for example if the onchange item is ci... and you add an option if they choose Cell phones... everytime they choose cell phones it will add that option even if it already exists... so they could end up with that option several times.. and you have to consider this when you write the code...
but bottom line yes add and remove are the best overall options...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-08-2015 11:16 PM
Exactly Doug, I'm facing addOption in an onChange script.
But if it is best practice as suggested from service now, we are lacking at number of lines writing in Client script..
For one of our service we have 4 select boxes which has dependencies of one or more options, if write add/remove are all it feels more number of code and as well as afraid of performance impact.
Anyway thanks! Looking for if there any enhancements comes with Fuji or Geneva.