UI Page - ui_reference search multiple fields

Tommy Jensen
Giga Guru

I know this question has been asked many times because I think I have read most of them by now but none of them have provided an answer that works for me.

Version: Jakarta paycj 10

On a UI Page I have following line

 

<g:ui_reference name="subject_person" id="subject_person" value="" displayValue="" table="sn_hr_core_profile" columns="employee_number;u_department" query="" completer="AJAXTableCompleter"  class="form-control" ref_ac_columns_search="true" ref_ac_columns="employee_number;ssn" />

I have also tried dot-walk in name like this "subject_person.ssn"

 

I need to search in name field, employee_number and ssn.

But search only occurs in name field.

The user must be able to find a hr profile on either name, ssn or employee_number. How do I do that in a UI Page. It works fine on a normal form.

 

4 REPLIES 4

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi Tommy,

have a look at the solution proposed to the following thread, it will show you how to do it easily:

multiple <g:ui_reference> fields in a UI page

If I have answered your question, please mark my response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thank you

Cheers
Alberto

That is NOT what I need.

 

I only have ONE reference field, I do not need multiple reference fields.

Jertay
Tera Contributor

It looks like this is not possible on UI Pages according to this site: https://www.snc-blog.com/2013/12/16/reference-field-searching/

I wonder if you could work around this using iframes or something, though that's not ideal. I'm dealing with this same limitation.

Joe72
Tera Contributor

After banging my head against a wall for a few hours, I did find a way to search by columns in a UI Page...

Long Story:

Unfortunately, the ui_reference macro and the AJAXReferenceCompleter [hidden] script include do not allow for you to pass in a columns_search="true" parameter. It would be an easy enough enhancement for ServiceNow to accomplish (it already allows you to pass in the table and columns), but at present, it doesn't work.

Once that was established (after much attempted shenanigans), it was apparent that the only way to pull off the column search was with a field that has the ref_ac_columns_search dictionary attribute set to true. So I created a test reference field on a table and pointed it to the table I wanted my ui_reference macro to point to in the UI Page. I set the ref_ac_columns and ref_ac_columns_search attributes for that reference field. I then got the name of that field: {table_name.field_name} and then set my ui_reference macro with the same name:

<g:ui_reference table="${table_name}" name="${table_name.field_name}" query="">

Viola! When doing its search, it now thinks its the field from the table and looks up its attributes and finds the ref_ac_columns_search and ref_ac_columns attributes:

find_real_file.png

Successful search on the 3rd column!

 

Short Story:

1) Create a reference or list (depending on the UI Macro being used) dictionary field on a table. You may already have one that works for your needs, so check before you create a new one. You do not need this field to be on a form anywhere, it just needs to exist.

2) Add the Dictionary Attributes for ref_ac_columns and ref_ac_columns_search.

3) In the UI Page or UI Macro, name the ui_reference field the name of the field created in step 1.

Limitations:

No matter what method tried, you cannot search on a dot-walked column. You can display a dot-walked value as a column, but you cannot search on it. If this is a must-have, you can always create a field to house the dot-walked value on the table you want to search for.

i.e., Let's say you wanted a ui_reference macro to point to the Incident table. You want to see the Caller ID and the Caller ID's city as columns in the auto-complete. You could see them as columns, but you wouldn't be able to search by city. You could create a city field on the Incident table and create a business rule to sync the Caller ID's city to that field. Then add that field to the columns list instead of the dot-walked field.