Auto-Complete on Catalog Reference Variables

Jim Coyne
Kilo Patron

The Auto-Complete feature with the AJAXTableCompleter is a nice feature in forms because you can add extra fields to display in the list to make it easier for users to tell similar items apart from one another (e.g. users with the same name).

Unfortunately, the feature is not available for Service Catalog variables - until now that is!!!

I wrote a UI Script that allows us to specify which columns to add to the list:


function u_enableAJAXTableCompleter(variableName, columns, orderBy) {
try{
var referenceFieldName = 'sys_display.' + g_form.getControl(variableName).name.toString();
var onfocusScript = $(referenceFieldName).readAttribute('onfocus').toString().replace('AJAXReferenceCompleter', 'AJAXTableCompleter');
if (Prototype.Browser.IE) {
var referenceField = document.getElementById(referenceFieldName);
var newOnFocusFunction = new Function(onfocusScript);
referenceField.ac_columns = columns;
referenceField.ac_order_by = orderBy;
referenceField.onfocus = newOnFocusFunction;
} else {
$(referenceFieldName).writeAttribute({ac_columns : columns, ac_order_by : orderBy, 'onfocus' : onfocusScript});
}
} catch(err) {}
}


The trick is to replace "AJAXReferenceCompleter" with "AJAXTableCompleter" and then add the columns. You just call it from an onLoad script with the name of the variable and the columns you want to add and the column to sort on:

function onLoad() {
u_enableAJAXTableCompleter('caller_id', 'email;phone;title;department', 'department');
}


Here's a screenshot of it running in a demo instance on the Create a new Incident record producer:

find_real_file.png

You can see the extra fields are being displayed and the data is sorted on the Department field.

Update: I still have not figured out how to allow the searching on the extra fields yet (ref_ac_columns_search=true). I've tried adding different combinations of "ref_ac_columns_search" and "ac_columns_search" as attributes without any luck.

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

So finally some good news, at least for Dublin users.   I just found out yesterday from a colleague of mine that it is now supported in Dublin.   It is a little misleading though.



Variables will inherit some of the attributes that may be defined as default attributes for the table (Auto-Complete for Reference Fields - ServiceNow Wiki), but searching on the extra columns will not work until you actually add the "ref_ac_columns" and "ref_ac_columns_search" attributes to the variable.



So, to add the ability to search the email address on a User reference variable when you have a default set on the User table (as per above wiki article), just add the "ref_ac_columns_search=true,ref_ac_columns=email" attributes to the variable.   If you do not have a default set, you will need the entire "ref_auto_completer=AJAXTableCompleter,ref_ac_columns=email,ref_ac_columns_search=true,ref_ac_order_by=name" attribute on the variable.


View solution in original post

21 REPLIES 21

Community Alums
Not applicable

Hi 

i have one requirment similar to this one but the reference table field name contains the special characters when i searched that name it was skipped, so i have to do?

example : catalog item : request something

variable :location (reference table cmn_location) in location table the name as "ap-ch-f1".

when i was searched on cat item for location just type "a".at that time i need see the entire name related to "a"

how to get the entire name without giving the full name

alexander_kulcz
Tera Contributor

Trying to do in Vancouver and... no luck!