Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Glide list reference qualifier

kunal16
Tera Expert

Hi All,

On Case form, I have created a Glide list field 'Feature' - this is reference to a custom table Product feature (u_product_feature). The Product Feature form has another reference field Product (u_product) - reference to cmdb_software_product_model.

Also, on the Case form, I have another reference field called Client deployment (reference to custom table u_cmdb_ci_client_deployment). The form (u_cmdb_ci_client_deployment) has a field called Product (reference to table cmdb_software_product_model).

So, if on any Case form, a value is selected against field Client deployment (and say it has Product = Pabc), then the value against the field Feature should only return those values which have Product = Pabc.

I wrote the below script include to achieve this and called that one as a reference qualifier onto the field Feature on the Case form but it seems its not working.

var myFeature = Class.create();

myFeature.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

  caseFT : function()

  {

  if (current.variables.u_client_deployment_id == '')

  {

  return;

  }

  var cdi = current.u_client_deployment_id.toString();

  if(cdi)

  {

  var ft1 = [];

  var gr = new GlideRecord('u_product_feature');

  gr.addQuery('u_product', cdi.u_product);

  gr.query();

  while (gr.next())

  {

  ft1.push(getValue('sys_id'));

  gs.info('@@ ' + ft1.push(getValue('sys_id')));

  }

  gs.info('@@ ' + ft1);

  return   ft1.toString();

  }

  },

  type: 'myFeature'

});

Any lead will be appreciated. Thanks in advance!!

1 REPLY 1

Geoffrey2
ServiceNow Employee
ServiceNow Employee

There are a few issues here:


  • You're calling current but it's not defined.   You need to pass it as a parameter when you call the function.   I normally use Script Includes (not Client-callable - although I don't think it matters here) with a Reference qualifier like the one below.
  • On line 10 you're defining cdi as a String, but then trying to dot-walk from it on line 17 with cdi.u_product
  • On lines 21 and 22 you're missing gr. in front of getValue('sys_id').   It should be gr.getValue('sys_id')
  • On line 25 you need to return an encoded query: 'sys_idIN' + listOfSysIds


Reference qualifier: javascript: new myFeature().caseFT(current);


Script Include:


var myFeature = Class.create();


myFeature.prototype = {


  initialize: function() {


  },



  caseFT: function(ritm) {



          var productID = ritm.variables.u_client_deployment_id.u_product.sys_id;



          if (!productID)


                  return '';



          var ft1 = [];


          var pf = new GlideRecord('u_product_feature');


          pf.addQuery('u_product', productID);


          pf.query();


          while (pf.next()) {


                  ft1.push(String(pf.sys_id));


                  gs.info('@@ ' + pf.sys_id);


          }


          gs.info('@@ ' + ft1);


          return 'sys_idIN' + ft1.join(',');


  },



  type: 'myFeature'


};