How to change drop down filed options based on the view ?

Adam61
Kilo Contributor

What is the best way to change drop down options when user changes the view?.

ex when user Change the view on the incident from self - service to different view show in a drop down field different options to select from . 

 

Thanks

1 ACCEPTED SOLUTION

Other things is more intresting . You can try with this . Becouse this is i have tried. 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 sanjay bagri..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'; } } } Please remember it mark it as correct and also helpful . Gaurented it will help you . Becose same thing i have done . In our project recently. Thanks Sanjay Bagri

View solution in original post

7 REPLIES 7

Other things is more intresting . You can try with this . Becouse this is i have tried. 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 sanjay bagri..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'; } } } Please remember it mark it as correct and also helpful . Gaurented it will help you . Becose same thing i have done . In our project recently. Thanks Sanjay Bagri

Thanks that was really helpful 

Tq . I got help from your answers.