Has anyone done a look up on a string field in a reference field?

Nivlac1000
Kilo Expert

So I have a requirement to do a look up on a sys_user reference field on a Catalog Item using an underlying string field in the User record.

We have lookup on the User Name on that table for auto-complete and the documentation shows the ability to auto-complete with another reference field on User, but not with a string field.   Auto-Complete for Reference Fields - ServiceNow Wiki

Anyone have a clue how to make this work for a string field?  

Thanks!

Cal

1 ACCEPTED SOLUTION

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Cal!   Its been a while, I hope you are doing well and enjoying this wonderful hot weather in NC!



I have set this up for several customers who say want to filter users based on their employee id number or location based off a location code.   Here are some instructions I put together that I shared internally may help you:



Use Case: I would like to search for callers by several attributes and not just by their name. OOB the user can click the magnifying glass beside the reference field and search that way, but it requires extra clicks and time.   Fortunately ServiceNow can display other data on the Type Ahead popup and that data is also searchable!


find_real_file.png



Notice above I am not only showing the employee's name, but also the first and last name as well as the employee number of that user.


·                 You can also set it up where you search all the columns you are displaying.   This comes in handy if the users want to be able to search on first name, last name, or employee ID all in the same field.   Also notice above, I typed in "111" and it searched both the employee ID column and presented several results where the employee number starts with "111". I could have also typed in "smi" to get the same results.


·                 This especially comes in handy with locations and wanting to search for a city or state or location code/number.



This is also very easy to configure with the steps below:


  1. Now I mentioned above to make sure the "number" field is a string value, the reason I mentioned this is because if you want to allow searching in all columns it must be a string type column.   Numbers, email, etc aren't searchable.
  2. To set this up, you personalize the dictionary on the particular field — this is done on a field by field basis so you may need to do this multiple times.   So for example, to make the above work for the incident caller, right click on the Caller label and choose Personalize Dictionary.   Then:
  3. Make sure you are on the Advanced View — under Related Links you may see "Advanced view" so click that if it shows up.
  4. On the Advanced view you will see a field called Attributes.   OOB the value of this field is: ref_contributions=user_show_incidents
  5. You will need to add a few new attributes which are always separated by commas, then paste in the following:

i. ref_ac_columns_search=true,ref_auto_completer=AJAXTableCompleter,ref_ac_columns=first_name;last_name;employee_number


ii.           Here is an explanation on what these mean:


  1. ref_contributions=user_show_incidents — this shows the UI Macro that shows all the caller's incidents
  2. ref_ac_columns_search=true,ref_auto_completer=AJAXTableCompleter — these allow the searching to happen
  3. ref_ac_columns=first_name;last_name;employee_number — this is how you set what additional columns appear.   In this example I am showing the first and last name and employee number.   You must enter the database column name, not the label.   You can certainly add additional ones by separating them with a semicolon.

iii.           The end result Attributes value will be:


ref_contributions=user_show_incidents,ref_ac_columns_search=true,ref_auto_completer=AJAXTableCompleter,ref_ac_columns=first_name;last_name;employee_number


View solution in original post

13 REPLIES 13

You are welcome Cal. I'm glad you got it figured out. Thanks for participating in the community.


Hi Michael Ritchie,
 
Hope you are still here.
 
I want to know if this can achieve in UI Page.
 
<g:ui_reference style="text-align:left;" id="user" width="100%" name="user"  table="u_mailroom_information"/>
 
I add a reference field in the ui page, and want to search user table by last_name first_name employee_number.
 
Waiting for your reply!
Thank you in advanced.
Bella,

Shuang, you just need to add these parameters:

query="encoded-query-if-needed" completer="AJAXTableCompleter" columns="columns-separated-by-semicolon"

Example using yours from above:

<g:ui_reference style="text-align:left;" id="user" width="100%" name="user"  table="u_mailroom_information" query="active=true" completer="AJAXTableCompleter" columns="first_name;last_name;employee_number"/>

 

morrix7
Kilo Contributor

What if there are multiple values inside the column? Like a metadata kind of thing,  lol,fun,times the attribute looking in this field only shows the first word (lol) but the result comes up empty when entering fun or times.