- 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
‎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
‎06-19-2014 11:18 PM
Works perfect! Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2015 07:27 AM
Hi Jim.
I tried exactly this approach and it isn't helping for me.
We have a form that has two fields: u_approver and u_category. u_approver is a reference to User form, and u_category holds the department they belong to.
We want the catalog variable to show the approver as well as the department he belongs to.
The catalog variable that I have is ref_auto_completer=AJAXTableCompleter,ref_ac_columns=u_category,ref_ac_columns_search=true,ref_ac_order_by=u_approver
This does not work at all. If I switch the u_category and u_approver on the attribute, it does work but you're primarily searching based on u_category and not u_approver as was intended.
The only other option is to have ref_ac_columns and re_ac_order_by both set to u_approver but we leave out the category completely which we don't want.
What am I doing wrong in this case?
thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2015 09:06 AM
Could it be possible that the use of a reference to a reference is screwing this up?
The form that I am using for the autocomplete is an intermediate form with uses the User form as a reference. Here we are trying to use a Service Catalog Variable to look up a staging form which contains u_approver, which itself is a reference to the User Form.
I ask this because I've noticed a bunch of problems with regards to people using this data, as they are not dot_walking towards the u_approver field instead relying on the parent record which is an incorrect reference and not the reference to the User field they are looking for. Is there any way to accomplish this through the auto-complete attributes?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-26-2017 06:48 AM
In my case its working f9 for user that have any role..... for end user its not working