Client script gliderecord getEncodedQuery being ignored when using query('x','y')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2017 05:06 PM
I noticed that while the following onchange client script is working, my getEncodedQuery is being ignored (no errors!) when using a normal query('x','y').
Code is as follows:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') { //Return out of this script when the form is initially loading (isLoading) or the new field value from "Field name" above is blank
return;
}
g_form.setValue('u_ci_list', ""); //Start with blanking out the asset list
populate_ci_list();
function populate_ci_list(){
var gr = new GlideRecord('cmdb_ci'); //Call the cmdb_ci table
var caller = g_form.getValue('caller_id'); //Grab the caller_id value
var encodedquerystring = "asset.u_computer_type=Personal PC^NQsys_class_name=cmdb_ci_peripheral";
gr.addQuery('assigned_to', caller); //Add a query of the 'assigned_to' field to the gr call
gr.getEncodedQuery(encodedquerystring);
gr.query(); //Do the query to the gr call
while(gr.next()) //Loop through the alm_asset table, which includes the query from above
{
g_form.setValue('u_ci_list', gr.sys_id); //When finding a matching item in the table with the query, set the 'u_assets' field to the data returned from the query
}
}
}
Any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2017 11:33 AM
Can an encoded query string not contain any spaces within a variable? My string that I'm looking for in the encoded query string does have a space in it, so removing it would not return the right results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2017 11:24 AM
Just getting back to this today... does anyone have any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2017 07:10 AM
Hi,
I think you meant (add)
gr.addEncodedQuery(encodedquerystring);
instead of (get)
gr.getEncodedQuery(encodedquerystring);
Let us know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 04:10 PM
Because this is a client script, I'm limited to gr.getEncodedQuery. Please correct me if I'm wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2017 04:55 PM
Hi Shane, getEncodedQuery will actualy get you a query string, you can't pass any parameter to it. In GlideRecord client side you should simply use addQuery(querystring), see https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=r_GRCS-addQuery_S . However this is no longer supported with GlideRecordV3 (not sure in which version it started to be V3).
As it is not supported in latest release, I think you have no choice to do it with a GlideAjax call.