How to hide a choice value on a reference field on a form

Jamie Sherry
Tera Contributor

I'm working on a form on the Incident table and I need to hide a value from the a dropdown field. I have a reference field on the form from the CI table called Operational Status. Operational Status is an integer field with choices, one of which is "retired". When selecting an option in the Operational Status field on the Incident form, I need to remove the option to select "retired".  How would I go about this?

1 ACCEPTED SOLUTION

yuvarajkate
Giga Guru

You can use Client Script for this.

Script:

function onLoad() {
    var operationalStatusField = g_form.getField('operational_status'); 
    if (operationalStatusField) {
        var options = g_form.getOptions('operational_status');
        for (var i = 0; i < options.length; i++) {
            if (options[i].text.toLowerCase() == 'retired') {
                g_form.removeOption('operational_status', options[i].value);
            }
        }
    }
}

 

Pease mark this as helpful or correct if this helped you in your problem.

View solution in original post

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

Hi Jamie,

You can do this with g_form.removeOption in a Client Script

https://www.servicenow.com/docs/bundle/xanadu-api-reference/page/app-store/dev_portal/API_reference/... 

That was the first thing I tried. I made an onLoad client script of 

g_form.removeOption('operational_status','6');
This didn't work however so I'm not sure what to try next. 

Yeah, when testing this I see that the dot-walking is not honoring this, or right-clicking on the label and configuring choices, which should also work.  When you choose a CI it's showing the Operational Status from that record, so are you really looking to filter retired CIs from the Configuration item field, or are you trying to update the Operational status of a CI from the incident record?

I'm looking to update the operational status of a CI from the Incident form. I don't want Retired to be a selectable option to update the CI.