Why Remove Option or AddOption is not working for catalog item?

Prathamesh Chav
Tera Contributor

Hi Team,

 

I am trying to add and remove option for region field but its not working

Trying this for catalog

 

function onLoad() {
    //Type appropriate comment here, and begin script below

    'Show "All India, Central" this two options in region variable for Selection'
   
    if(g_form.getValue("region")== null){
    g_form.removeOption("region","All Region", 'All Region');
     
    }
   
}

PrathameshChav_1-1737965393481.png

 

 

3 REPLIES 3

Voona Rohila
Kilo Patron
Kilo Patron

Hi @Prathamesh Chav 

 

Please comment line 4 from your code and modify line 6,7 as below.

function onLoad() {
    //Type appropriate comment here, and begin script below

  //  'Show "All India, Central" this two options in region variable for Selection'
   
    if(g_form.getValue("region") == ''){
           g_form.removeOption("region","All Region");
     
    }
   
}

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

abhi159
Kilo Sage

@Prathamesh Chav  

 if(g_form.getValue("region")== null) remove null by empty space this will not working because of null.use this  if(g_form.getValue("region")== ' ') 

Please mark this response as correct or helpful if it assisted you with your question.

 

   
     

Juhi Poddar
Kilo Patron

Hello @Prathamesh Chav 

  • Try this updated client script:
function onLoad() {
    if (!g_form.getValue("region")) {
//    'Show "All India, Central" this two options in region variable for Selection'
        g_form.removeOption("region", "All Region");
    }
}
  • Syntax for g_form.removeOption() method:
g_form.removeOption(fieldName, optionValue);
  •  Comments should always start with //

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar