Filter a dropdown field in Service Portal

Jo_o Luis
Tera Contributor

I want to filter "Area / Subject / Expertise" field depending on the "Country for F.M.V calculation" field. So if I select for example "Albania" it should appear only relevant options in "Area / Subject / Expertise" field. How do I do that?

 

 

 

Jo_oLuis_0-1697193337358.png

 

2 ACCEPTED SOLUTIONS

Ok...the "country_for_fmv_calculation" is not Reference variable on catalog item....right...??

Can you try like below.....!!

 

javascript:'country.name=' + current.variables.country_for_fmv_calculation;

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

Hi @Jo_o Luis 

 

As it's reference field, It will be difficult.

What I suggest is if possible, make the field type as "Lookup select box" & use "unique values only" option.

e.g.,

The screenshot below is just example...You can use your table & lookup value which you want to display.

 

VishalBirajdar_0-1697451055330.png

 

 

 

 

 

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

View solution in original post

14 REPLIES 14

kamlesh13
Tera Contributor

Hey @Jo_o Luis,

 

Is it catalog item you using the portal? or the values from the form?

 

Regards,

Kamlesh

Samaksh Wani
Giga Sage
Giga Sage

Hello @Jo_o Luis 

 

Use Catalog Client Script :- OnChange Script.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

   if ( isLoading || newValue == '') {
      return;
          }
}

var con = g_form.getDisplayBox('country_field_name').value;

if (con == 'Albania'){
g_form.clearOptions('area_field_name');
g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>);  // option 1
g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>); // option 2
g_form.addOption(<fieldName>, <choiceValue>, <choiceLabel>, <targetIndex>); // option 3
}

}

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

 

I have a table with all options corresponding to a different countries... should I do a GlideRecord and then create an array to push all options that correspond to that country?

 

  var s = g_form.getValue('country_field_name');
    var array = [];
   var gr = new GlideRecord ('table');
    gr.query();

    while(gr.next()){

        if (s == gr.getValue('country_table_field') ){

            array.push(gr.getValue('area_table_field'));
            g_form.setDisplay('area_field_name', array );
        }

    }

 

Hello @Jo_o Luis 

 

You can't do GlideRecord in client script.

 

You need to use script include for the same.

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh