Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Client script gliderecord getEncodedQuery being ignored when using query('x','y')

SC10
Kilo Guru

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?

10 REPLIES 10

SC10
Kilo Guru

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.


Just getting back to this today... does anyone have any ideas?


danilo21
Kilo Contributor

Hi,



I think you meant (add)



gr.addEncodedQuery(encodedquerystring);



instead of (get)



gr.getEncodedQuery(encodedquerystring);



Let us know.


Because this is a client script, I'm limited to gr.getEncodedQuery. Please correct me if I'm wrong.


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.