- 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
‎11-02-2012 07:09 AM
I set it up in demo04. Take a look at the Create a new incident record producer. Take a look at the "Open on behalf of this user" variable.
UI Script - https://demo04.service-now.com/nav_to.do?uri=sys_ui_script.do?sys_id=97c2ea84b861300000a28abf3b756cca
Catalog Client Script - https://demo04.service-now.com/nav_to.do?uri=catalog_script_client.do?sys_id=c123ee44b861300000a28abf3b756c58
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2012 08:27 AM
this is really weird Jim... i deleted everything I did before and started all over again, copying exactly how you had it set up in demo4, all i needed to change was the variableName (instead of CallerID i had something else) and it now works....?! totally did my head in, trouble is, i thought i had it just as you mentioned in this post.. hmmm maybe i had a character wrong somewhere!?! dont know how when copy and paste did it all for me.....
anyway, many thanks Jim, this will go a LONNNNG way for us! cheers 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2012 10:02 AM
Glad it works now, but take a look at my latest comment on the post --> you no longer need the script with Berlin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2012 04:48 PM
Thanks Jim.
We're still waiting for Berlin??? Service-now will not give me a def date but I've now been advised by our SNc Support Partner that we should get it around early Decemeber.... Then again, I've been told different dates for the past 2 months and still waiting.....
anyway, thanks for the script. funny thing is by the time I go live with the development I am doing I wont need it, IF we get Berlin by the end of the year that is.. 😕
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2012 10:01 AM
Just wanted to point out that this script is no longer needed with Berlin (not sure which exact Path/Hotfix). You can now specify it on the "Variable attributes" field of the Variable form. So to show the user's Email address, Title and Department in the drop down and sort by the Department field, you can now specify:
"ref_auto_completer=AJAXTableCompleter,ref_ac_columns=email;title;department,ref_ac_order_by=department"
right in the "Variable attributes" field.
For some reason the "ref_ac_columns_search=true" setting still does not work.
It's always better to use the built-in functionality, but the script is definitely useful for pre-Berlin instances.