- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2012 02:52 PM
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:
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2014 10:25 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2012 01:26 PM
Very cool!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2012 02:58 AM
I wonder how to configure the Auto-Complete in Reference Variables to Match Text From Any Reference Field displayed using ac_columns.
I tried amending the UI Script as follows:
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.ac_columns_search=true;
referenceField.onfocus = newOnFocusFunction;
} else {
$(referenceFieldName).writeAttribute({ac_columns : columns, ac_order_by : orderBy, ac_columns_search : true, 'onfocus' : onfocusScript});
}
} catch(err) {}
}
And it displays additional columns but does not search over additional columns. Any hint?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2012 07:38 AM
Still no luck with the "ref_ac_columns_search" option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2012 11:18 PM
Hi Jim,
I'm struggling to get this script to work in my instance, can you point me to the demo instance you have this script working on please?