- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2014 02:06 PM
Hello Community,
I am creating a custom search on a UI Page. I have a single text box for input. After you type at least 3 characters, it triggers a timer for 2 seconds, then it automatically builds an encoded query using the search terms entered and runs that query to the sc_cat_item table against the meta fields to find related records using GlideAjax. The script creates <div> elements on the UI Page and sets the text inside of those DIVs to the name of the catalog items returned. There are a couple of problems I've run into so far..
1) I'm getting multiple queries running after the timeout period ends. If I typed "password" into the search, it will run the query 8 times (once for each letter) instead of just once for the word.
2) If I typed "password verizon", it will only return the records relevant to the term "password" instead of both terms.
3) Even using an Encoded Query, i'm not getting accurate search results. If I create a GlideRecord query using the 'Background Scripts' module, and insert the same encoded query, i get accurate results. When it runs via GlideAjax on the UI Page, i don't get the same results.
The script that i'm using is a simple GlideRecord query...
var ir = new GlideRecord('sc_cat_item');
ir.addEncodedQuery('metaLIKEpassword^ORmetaLIKEverizon');
ir.query();
while(ir.next()){
return ir.name;
}
Any suggestions on any of these problems?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2014 10:39 PM
Hi Kenneth,
I can't see anything immediately wrong with your ajax function, except that _getUserGroups() has no return value. Try adding the following statements in red text.
getUserGroups: function(myUser){
myUser = this.getParameter('sysparm_user');
gs.log('getUserGroups() parameter myUser: '+myUser);
return this._getUserGroups(myUser);
},
_getUserGroups: function(myUser){
gs.log('_getUserGroups() parameter myUser: '+myUser);
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user',myUser);
gr.query();
gs.log('_getUserGroups() getRowCount(): '+gr.getRowCount());
var groupsArray = [];
while(gr.next()){
//gs.log("SCRIPT INCLUDE :" + gr.group);
groupsArray.push(gr.group.sys_id.toString()); // collect sys_id values in array of string values
}
gs.log('groupsArray: '+groupsArray.toString());
return groupsArray.toString();
}
Check that all of the log statements make it to the system log. Confirm the row count value as this will tell you how many results were returned by the query, and then check the final log statement, which should be a comma separated list of sys_id values (the same number as the row count etc). After the final log statement, I've added a return statement which should return the comma separated string of sys_id values, to the first function (getUserGroups()). That function should return the value to your client side function.
Regards,
Jake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2016 08:57 AM
Kenneth, how did you get rid of that log entry:
syslog_transaction not found for AjaxClientTiming: sysId: , table: , view: Default view, form: ui_page_render ?
I'm getting it every time I load my new UI Page that calls a GlideAjax, even though the button that sends the ajax hasn't been clicked yet.
