show values in reference field search based upon the choices in another field

kiran kumar m1
Tera Contributor

I have 2 fields one is Geo (choice) field and another is location(reference) field . In my location field i have over rided the reference qualifier and kept 3 locations India, Philippines, Mexico . Now in geo field i have two options NA and APAC . Now I need a functionality such that if I select NA in the geo field the search box in the location field should have only Mexico as location to select similarly if i select APAC only India and Philippines should be visible to select .   How can I achieve this ?

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You should be able to do this all within the reference qualifier like this:

BradBowman_0-1726875345371.png

 

var ret='sys_idIN';if(current.u_geo == 'NA'){ret += 'sys_id of Mexico';}else{ret += 'sys_id of India, sys_id of Philippines';}ret;

 

Where u_geo is the choice field name, which has the actual value of 'NA', 

View solution in original post

9 REPLIES 9

Hi @Brad Bowman  I have tried the reference qualifier provided by you   

var ret='sys_idIN';if(current.geo == 'NA'){ret += '7f7d7db1db59c450462e771c8c9619d8';}else{ret += '7b7d7db1db59c450462e771c8c9619d3', '87e28ef5db59c450462e771c8c9619ea';}ret;

 

I even tried removing the var ret in the beginning but no use  its showing all the locations 

 

my geo field   (GEO/geo)(label/value)

choices 

NA/na

APAC/apac

 

Do you have the javascript colon in front of that from my screenshot?  It translates incorrectly if typed in this editor is why I left it out of the code box.  You should use 'na' since that is the choice value.  Have you tested by selecting both choices?

yeah I have tried selecting both choices even I have kept the value na 

Thanks @Brad Bowman  it was my bad . Now the solution is working fine . Thankyou for your help.

Sandeep Rajput
Tera Patron
Tera Patron

@kiran kumar m1 Ideally the solution suggested by Brad should work. In case if you are finding it difficult to make the reference qualifier work, I recommend you to create a script include, put your logic inside the script include method and call the script include method inside the reference qualifier.

 

You can use this thread https://www.servicenow.com/community/developer-forum/how-to-write-advanced-reference-qualifier-scrip... as a reference to know how advanced reference qualifier using script include can be created.

 

Hope this helps.