The CreatorCon Call for Content is officially open! Get started here.

Count by location help

coolgirl
Mega Expert

Hi,

      I am working on map pages. I am trying to replicate the code in 'incident count by location' by giving a different table name but it does not seem to work. May i know where am i going wrong.

This is the code

var uri = gs.getProperty("glide.servlet.uri");  

var count = new GlideAggregate('u_leads');         //u_leads is the table which has the field location

count.addAggregate('COUNT', 'location');

count.query();

 

while (count.next()) {  

 

      var loc = count.location;

      var locCount = count.getAggregate('COUNT', 'location');  

 

      if (locCount > 0) {  

 

              var item = map.addItem(count);  

 

              item.latitude = loc.latitude;  

              item.longitude = loc.longitude;  

              item.marker_label = locCount;    

              var link = 'href=' + uri + 'u_leads_list.do?sysparm_query=location%3D' + loc;  

              item.html = '<a ' + link + '>' + loc.getDisplayValue() + ' (' + locCount + ') </a>';

              item.icon = "/star.png";  

              item.icon_width = 20;  

              item.icon_height = 20;  

      }  

}  

Thanks,

Sam

1 ACCEPTED SOLUTION

Hi Sam,



Not that used to the Aggregate method but here's what I ended up with:


I used a variable u_status that is true or false, so you can replace the true/false with the value of your Status variable(completed, open, closed....)



  1. var uri = gs.getProperty("glide.servlet.uri");
  2. var count = new GlideAggregate('u_leads');
  3. count.addAggregate('COUNT', 'u_location');
  4. count.query();
  5. while (count.next()) {
  6.   var loc = count.u_location;
  7.   var locCount = count.getAggregate('COUNT', 'u_location');
  8.   var locOpen = 0;
  9.   var locClose = 0;
  10.   //COUNT THE STATUS = TRUE RECORDS
  11.   var counto = new GlideAggregate('u_leads');
  12.   counto.addQuery('u_location', loc);
  13.   counto.addQuery('u_status','true');
  14.   counto.addAggregate('COUNT');
  15.   counto.query();
  16.   if (counto.next()){
  17.   locOpen = counto.getAggregate('COUNT');
  18.   }
  19.   //COUNT THE STATUS = FALSE RECORDS
  20.   var countc = new GlideAggregate('u_leads');
  21.   countc.addQuery('u_location', loc);
  22.   countc.addQuery('u_status','false');
  23.   countc.addAggregate('COUNT');
  24.   countc.query();
  25.   if (countc.next()){
  26.   locClose = countc.getAggregate('COUNT');
  27.   }
  28.   if (locCount > 0) {
  29.   var item = map.addItem(count);
  30.   item.latitude = loc.latitude;
  31.   item.longitude = loc.longitude;
  32.   item.marker_label = (locCount);
  33.   item.label_offset_left = -11000;
  34.   item.label_offset_top = -2210;
  35.   var link = 'href=' + uri + 'u_leads_list.do?sysparm_query=u_location%3D' + loc;
  36.   item.html='<a ' + link + '>' + loc.getDisplayValue() + ' (' + locCount + ') - Open = ' + locOpen + ' - Close = ' + locClose + ' </a>';
  37.   item.icon = "images/red_marker.png";
  38.   item.icon_width = 50;
  39.   item.icon_height = 50;
  40.   }
  41. }


find_real_file.png find_real_file.png


find_real_file.pngfind_real_file.png



Thank you for marking the question as resolved



Harry


View solution in original post

11 REPLIES 11

Hi Sam,



Not that used to the Aggregate method but here's what I ended up with:


I used a variable u_status that is true or false, so you can replace the true/false with the value of your Status variable(completed, open, closed....)



  1. var uri = gs.getProperty("glide.servlet.uri");
  2. var count = new GlideAggregate('u_leads');
  3. count.addAggregate('COUNT', 'u_location');
  4. count.query();
  5. while (count.next()) {
  6.   var loc = count.u_location;
  7.   var locCount = count.getAggregate('COUNT', 'u_location');
  8.   var locOpen = 0;
  9.   var locClose = 0;
  10.   //COUNT THE STATUS = TRUE RECORDS
  11.   var counto = new GlideAggregate('u_leads');
  12.   counto.addQuery('u_location', loc);
  13.   counto.addQuery('u_status','true');
  14.   counto.addAggregate('COUNT');
  15.   counto.query();
  16.   if (counto.next()){
  17.   locOpen = counto.getAggregate('COUNT');
  18.   }
  19.   //COUNT THE STATUS = FALSE RECORDS
  20.   var countc = new GlideAggregate('u_leads');
  21.   countc.addQuery('u_location', loc);
  22.   countc.addQuery('u_status','false');
  23.   countc.addAggregate('COUNT');
  24.   countc.query();
  25.   if (countc.next()){
  26.   locClose = countc.getAggregate('COUNT');
  27.   }
  28.   if (locCount > 0) {
  29.   var item = map.addItem(count);
  30.   item.latitude = loc.latitude;
  31.   item.longitude = loc.longitude;
  32.   item.marker_label = (locCount);
  33.   item.label_offset_left = -11000;
  34.   item.label_offset_top = -2210;
  35.   var link = 'href=' + uri + 'u_leads_list.do?sysparm_query=u_location%3D' + loc;
  36.   item.html='<a ' + link + '>' + loc.getDisplayValue() + ' (' + locCount + ') - Open = ' + locOpen + ' - Close = ' + locClose + ' </a>';
  37.   item.icon = "images/red_marker.png";
  38.   item.icon_width = 50;
  39.   item.icon_height = 50;
  40.   }
  41. }


find_real_file.png find_real_file.png


find_real_file.pngfind_real_file.png



Thank you for marking the question as resolved



Harry


Thank you Harry for the help.