remove a dropdown option from the choice list

Prasnajeet1
Giga Guru

Hi All

I have a small query.

I am writing a onChange client script. my requirement is if "model_category" = "computer" then I need to remove a option from the "substatus" field in the alm_hardware table. model_category is a read-only reference field.

Below is my script.

onChange client script: is not working.

field: State

unction onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (g_form.getValue('model_category') == '81feb9c137101000deeabfc8bcbe5dc4') {
        alert('test');
        g_form.removeOption('substatus', 'lease_return');
    }
Above script is working in onLoad client script but not working in OnChange client script. Can someone please help me. Where I am doing wrong or what need to change in it.
 
function onLoad() {
    //Type appropriate comment here, and begin script below
    if (g_form.getValue('model_category') == '81feb9c137101000deeabfc8bcbe5dc4') {
       g_form.removeOption('substatus', 'lease_return');
    }
}

}
1 ACCEPTED SOLUTION

@Prasnajeet1 , I just checked in my PDI so in your case in alm_hardware the substate is a dependent field on state so i tried onchange of state checked model category the choice value is not getting removed or getting added you can remove dependent value in substate but it will change for every model category.

 

if it is a dependent value then removeOption will work on onload but not on onchange so you might have to write a combo of both or as workaround if you know on which State choice you want to remove the option write it in onload client script only.

 

Servicenow 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0681253

 

Regards,

Swathi Sarang

View solution in original post

6 REPLIES 6

swathisarang98
Giga Sage
Giga Sage

Hi @Prasnajeet1 ,

 

In on change are you getting the alert ?

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

Hi Swathi

Yes I am getting the alert message.

 

@Prasnajeet1 , I just checked in my PDI so in your case in alm_hardware the substate is a dependent field on state so i tried onchange of state checked model category the choice value is not getting removed or getting added you can remove dependent value in substate but it will change for every model category.

 

if it is a dependent value then removeOption will work on onload but not on onchange so you might have to write a combo of both or as workaround if you know on which State choice you want to remove the option write it in onload client script only.

 

Servicenow 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0681253

 

Regards,

Swathi Sarang

@Prasnajeet1 , If the workaround also doesn't work you might have to raise HI ticket.

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang