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

Chuck Tomasi
Tera Patron

Hi Cal,



Can you clarify? Screenshots would be nice. I'm afraid I do not understand the issue.



For what it's worth, you CAN use string fields in the auto-complete/search attributes on a reference field. For example, you can lookup a user by the email address when searching for a caller on an incident, or an employee ID works well too - both are string fields.


Hey Chuck,


So the ref field on the form points to sys_user and instead of looking up by Name, they want to look up the user record by the Oracle ID, which is a string field. The documentation tells how to do this if it's another reference field, like Department.


oracle ID.png


Thanks!


Cal


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


Doing great Michael! Always super hot here in NC.


Feel like the royal treatment today you and ctomasi responding in like 2 seconds of each other!


Thanks guys, going to try this now!