How to disable select field option?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 02:54 PM
We were using a script from servicenowguru to Disable/Enable Select Option.
Suddenly, after Jakarta upgrade, it stopped working.
Tried jQuery and DOM way to put it to work, but could not. Did anyone have this issue and solved it?
please share you thoughts.
In this picture, Pre-Approved must be greyed out, it was and not anymore.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2017 03:04 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 02:32 PM
Brian,
It works when I do inspect element and add the attribute.
But does not work on a client script.
I tried all the options..
function onLoad() {
//disableOption('type', 'Pre-Approved'); // Calling UI Script
var op = document.getElementById('change_request.type').getElementsByTagName('option');
for (var i=0; i<op.length; i++) {
if(op[i].value == "Pre-Approved") {
alert(op[i].value);
//op[i].setAttribute("disabled", "true");
op[i].disabled = 'true';
}
}
//alert("Value: " + jQuery("#change_request.type option[value*='Pre-Approved']").prop('disabled',true));
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:51 PM
hi Rajinis,
you are right, seems like the OOTB change request type field option does not allowed disabled attribute.
If you really wanted this features, what I can think of is to create another field (e.g. type2) and i tested it can be disabled.
Just that you will need to link it back to the OOTB type field using on change script.
Client Script on load:
var op = document.getElementById('change_request.u_type2').getElementsByTagName('option');
for (var i=0; i<op.length; i++) {
if(op[i].value == "2") {
alert(op[i].outerHTML);
op[i].disabled = 'true';
}
}
I am on Jakarta version well.
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 08:38 PM
Hi Rajinis,
I will recommend if you don't want user to select the option in dropdown, You can use "addOption()" or "removeOption()" functions to achieve this. It is not best practice to play with DOM. Let me know in case of any concern.