GlideAggregate can it work with dot walking?

tahnalos
Kilo Sage

I have the following code in a script include.

updateCount : function (d1_id, mtype)

{

  var count = new GlideAggregate ('u_ScanSearch');

  count.addQuery ('parent', d1_id);

  count.addQuery ('u_searchType.u_mtype', mtype);

  count.addAggregate ('COUNT');

  count.query ();

  gs.log (d1_id + ' ' + mtype + ' ' + count.getAggregate ('COUNT'));

  return parseInt (count.getAggregate ('COUNT'));

},

I am aware that getAggregate returns a string.   Unfortunately the count.getAggregate lines both return nulls.   I'm suspecting that u_searchType may be the culprit.   mtype is supposed to be the display value of the reference field u_searchType (which has its own form u_searchType.   Under GlideRecord, I can get this type of query to work, but it doesn't seem to be working for Aggregate.

Can someone confirm if GlideAggregate can work with dot walking?   Or if not, can someone recommend an alternate approach?

Thanks

1 ACCEPTED SOLUTION

Little correction -   count.next()


View solution in original post

8 REPLIES 8

josh_nerius
ServiceNow Employee
ServiceNow Employee

Hello,



Dot-walking should be supported in this case. I believe I may see the issue though: table and field names in ServiceNow are all lower case. In your script, you're using camel case "u_ScanSearch" and "u_searchType". Try changing all table/field names to lower case and see if this clears things up.


Sorry.   Should have mentioned that these names are slightly altered from their original so as to not violate their NDA.   In any case, the original names were completely in lowercase and still fail.


Hello,



The GlideAggregate class is an extension of GlideRecord and allows database aggregation, so it should work the way GlideRecord works. Can you please put some logs and check if it captures anything in log.



  1. updateCount : function (d1_id, mtype)  
  2. {  
  3.   gs.log('d1_id' + d1_id);
  4.   gs.log('mtype' + mtype);
  5.   var count = new GlideAggregate('u_ScanSearch');
  6.   count.addQuery('parent', d1_id);  
  7.   count.addQuery('u_searchType.u_mtype', mtype);  
  8.   count.addAggregate('COUNT');  
  9.   count.query ();  
  10.   gs.log(count.getRowCount());
  11.   gs.log(count.u_searchType.u_mtype);
  12.   gs.log (d1_id + ' ' + mtype + ' ' + count.getAggregate('COUNT'));  
  13.   return parseInt(count.getAggregate('COUNT'));  
  14. },

Little correction -   count.next()