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

Sanjay Bagri1
Tera Guru
Tera Guru
Hi, If you want in navigator then you can do this way . I think we can decide that view based on the order. We can change the view from self service by module order we can set . Then it will change . For example: how to display drop down values dynamically based on another field selection? I have 2 drop down fields. First drop down has 2 choices(value 1 and value 2). second drop down has 10 values. If I select value 1 from first dropdown, I want to display second drop down with only few related choices out of available 10 Please go through this way . Other way is if you want to change in any field then you can do this way . You'll want to modify the sys_choice table records with dependent values. The dependent values will be the "value" or "sys_id" data of the record you're referencing. See my post below for examples of how we did this. Open this bilow link . Multi-field sys_choice dependency If it is helpful for you . Please mark as correct and helpful or like. Thanks Sanjay Bagri

Hi Sanjay,

thanks for your replay, the problem now I want to change the choice list based on the view name of the form not anther field in the form ? Is there away to do this without heavy scripting ?

 

Thanks

and one other thing , I can't find the link in your replay , can you please update that ?

This is a link for that https://community.servicenow.com/community?id=community_question&sys_id=cc30c761db98dbc01dcaf3231f961978 Restrict available options to a dropdown field in a list https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/administer/contextual-security/concept/access-control-rules.html?title=Using_Access_Control_Rules And also we can restrict the dropdown values based on the role through clients script