Reference qualifier for lookup select box in servicenow

Mark Wood
Tera Contributor

Hello Experts, I have two lookup select box fields in Catalog Item. First one is Country and another one is State. So when I select a country in Country field, then only states of that country should populate in State field using 'cmn_location' table data. To achieve this I have created one Script Include and called it in Reference Qualifier.

 

When I test this Script Include in Background Script, I'm getting only states of that country returned.

 

But when I call it in State lookup field using Reference Qualifier, I'm still getting all states populated..

And I have attached screenshot for reference.

 

SS1 :- Variables

SS2 :- Script Include

SS3 :- Calling Script Include using Reference Qualifier

 

 

Thank You !!

8 REPLIES 8

Hello @Mark Manders ,

 

Pradnyesh
Kilo Sage

Hello @Mark Wood ,
Instead of taking array take a string and store the sys_id of the states in it with comma separated values,

And while return from script include use the following syntax :

return 'sys_idIN' + opt;                                     //opt = string variable.

Script include should be client callable and after that select the role also to run that script for.
And the syntax of the reference qualifier should be : 
javascript: new scriptIncludeName().functionName(passed value that you want to use in script include.);

If your problem solve with above solution please mark my answer as helpful.

Rohit99
Mega Sage

Hi @Mark Wood,

You may try with the following solution.

In reference qualifier instead of calling script you can directly write the 
javascript:"country="+current.variables.enter_country; //here "enter_country" is backend name of my country lookup box.

 

Rohit99_0-1723539827166.png

 

Rohit99_1-1723541281963.png

 

 

Please mark my response as correct and helpful if it helped solved your question.

 

Thanks,

Rohit Suryawanshi

 

 

 

 

 

 

Amit Verma
Kilo Patron
Kilo Patron

Hi @Mark Wood 

 

Assuming you have two lookup select box variables for Country and State respectively, you need to make use of the below Advanced Reference Qualifier in the State field to populate State based on country :

 

AmitVerma_1-1723624594562.png

 

javascript:"country="+current.variables.country.getDisplayValue(); //Assuming country is the name of the Country variable.

 

Output :

AmitVerma_2-1723624691113.png

 

Thanks and Regards

Amit Verma


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