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.

GlideAggregate not working on dot walked variable?

agoel
Kilo Explorer

Function below outputs the correct count of each "u_process_attribute.u_name" however it doesn't print the name of the u_process_attribute.u_name. Thoughts?

getRating: function(assessment) {

var assessment_sys_id = assessment; // Change this to do calculations on other assessments

  var count = new GlideAggregate('u_itsm_question_instance');

count.addQuery('u_assessment', assessment_sys_id);

count.addAggregate('COUNT', 'u_question_definition.u_process_attribute.u_name');

count.query();

while (count.next()) {

  var categoryCount = count.getAggregate('COUNT', 'u_question_definition.u_process_attribute.u_name');

  gs.log("There are currently " + categoryCount + " questions with a process attribute of " + count.u_question_definition.u_process_attribute.u_name);

}

    return;

}

Below is the output:

There are currently 3 questions with a process attribute of

There are currently 4 questions with a process attribute of

There are currently 2 questions with a process attribute of

There are currently 3 questions with a process attribute of

There are currently 3 questions with a process attribute of

There are currently 5 questions with a process attribute of

There are currently 8 questions with a process attribute of

There are currently 2 questions with a process attribute of

There are currently 3 questions with a process attribute of

There are currently 2 questions with a process attribute of

There are currently 2 questions with a process attribute of

There are currently 9 questions with a process attribute of

There are currently 2 questions with a process attribute of

There are currently 3 questions with a process attribute of

There are currently 5 questions with a process attribute of

There are currently 7 questions with a process attribute of

There are currently 4 questions with a process attribute of

There are currently 5 questions with a process attribute of

There are currently 12 questions with a process attribute of

There are currently 1 questions with a process attribute of

1 ACCEPTED SOLUTION

tltoulson
Kilo Sage

Hi Ashish,



I have had a similar experience with GlideAjax and one weird quirk is that in this case you have to use the getValue function to retrieve your dot walked value.   I am not sure why this is the case, possibly a detail in the object relational mapping, but I do know that this does tend to work:



getRating: function(assessment) {


var assessment_sys_id = assessment; // Change this to do calculations on other assessments


  var count = new GlideAggregate('u_itsm_question_instance');


count.addQuery('u_assessment', assessment_sys_id);


count.addAggregate('COUNT', 'u_question_definition.u_process_attribute.u_name');


count.query();



while (count.next()) {


  var categoryCount = count.getAggregate('COUNT', 'u_question_definition.u_process_attribute.u_name');


  gs.log("There are currently " + categoryCount + " questions with a process attribute of " + count.getValue('u_question_definition.u_process_attribute.u_name'));


}


  return;


}



Notice the change on line 10.


View solution in original post

4 REPLIES 4

tltoulson
Kilo Sage

Hi Ashish,



I have had a similar experience with GlideAjax and one weird quirk is that in this case you have to use the getValue function to retrieve your dot walked value.   I am not sure why this is the case, possibly a detail in the object relational mapping, but I do know that this does tend to work:



getRating: function(assessment) {


var assessment_sys_id = assessment; // Change this to do calculations on other assessments


  var count = new GlideAggregate('u_itsm_question_instance');


count.addQuery('u_assessment', assessment_sys_id);


count.addAggregate('COUNT', 'u_question_definition.u_process_attribute.u_name');


count.query();



while (count.next()) {


  var categoryCount = count.getAggregate('COUNT', 'u_question_definition.u_process_attribute.u_name');


  gs.log("There are currently " + categoryCount + " questions with a process attribute of " + count.getValue('u_question_definition.u_process_attribute.u_name'));


}


  return;


}



Notice the change on line 10.


Agree with Travis.


Just tried this solution and it worked!



Thanks Travis and Saritha!


vinothkumar
Tera Guru

Hi, 

 

I am stuck up with the similar thing, I want to replace the location field with caller's location in the below script, however if I do it is not working. Can you please help me, we are not using location field on the incident and it has to be done with callers location.

 

When I enter dot walking it is returning the record, but I am missing, some where, so posted the original OOB code, itself, can any one help me

 

 

//get the instances url so we can link back to it
var uri = gs.getProperty("glide.servlet.uri");
//create an aggregate query on the incident table
var count = new GlideAggregate('incident');
//set condition for active incidents
count.addQuery('active', 'true');
//set aggregate field to location to get count by location
count.addAggregate('COUNT', 'location');
//execute the query
count.query();

//loop through the results
while (count.next()) {

//get the current record's location
var loc = count.location;
//get the count of incidents for this locationa
var locCount = count.getAggregate('COUNT', 'location');
//only display location is there are active incidents
if (locCount > 0) {
//create new new map item for this location
var item = map.addItem(count);
//set lat/long from the location record
item.latitude = String(loc.latitude);
item.longitude = String(loc.longitude);

//create a marker label with the count
item.marker_label = locCount;
//define label offset for proper position
item.label_offset_left = -4;
item.label_offset_top = -20;

//option to define table and record for label hyperlink
//setting table and sys_id will override the use of html parameter
//item.table = 'cmn_location';
//item.sys_id = loc;

//build the link to the list of incidents for the location
var link = 'href=' + uri + 'incident_list.do?sysparm_query=active%3Dtrue^location%3D' + loc;
//build the html value to be displayed when you click the map icon
item.html='<a ' + link + '>' + loc.getDisplayValue() + ' (' + locCount + ')</a>';

//link to the icon image
item.icon = "images/red_marker.png";
//set the size of the icon based on the number of active incidents
item.icon_width = 24;
item.icon_height = 24;

}
}