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

Bharath40
Giga Guru

Hi Shane,



Line 13 in encodequerystring i see space for Personal PC is this as expected ?


Yes as the string result is exactly "Personal PC".


Harish KM
Kilo Patron
Kilo Patron

There is a space in below query. Encoded query will not have space


var encodedquerystring = "asset.u_computer_type=Personal PC^NQsys_class_name=cmdb_ci_peripheral";


// replace to below


var encodedquerystring = "asset.u_computer_type=PersonalPC^NQsys_class_name=cmdb_ci_peripheral";


Regards
Harish

Would that then not return my result? The string is exactly "Personal PC".