Count and display incident categories (group By) from incident table (use Glide Aggregate)

Ramachandra
Tera Contributor
 
1 ACCEPTED SOLUTION

Anusha Reddy VK
Mega Guru

Hi @Ramachandra  ,

 

Here is an example of Background script on how to display count and categories from Incident Table using Glide Aggregate:

 

// Create a new GlideAggregate object for the 'incident' table
var ga = new GlideAggregate('incident');

// Group by the 'category' field
ga.groupBy('category');

// Count the number of incidents in each category
ga.addAggregate('COUNT');

// Query the table
ga.query();

// Iterate through the results and display the category and the count
while (ga.next()) {
    var category = ga.getValue('category');
    var count = ga.getAggregate('COUNT');
    
    gs.print('Category: ' + category + ', Count: ' + count);
}

 

 

Result:

AnushaReddyVK_0-1716886937656.png

 

If you find my response helpful, please consider selecting "Accept as Solution" and "Helpful" .

 

Thanks,

Anusha

View solution in original post

4 REPLIES 4

Anusha Reddy VK
Mega Guru

Hi @Ramachandra  ,

 

Here is an example of Background script on how to display count and categories from Incident Table using Glide Aggregate:

 

// Create a new GlideAggregate object for the 'incident' table
var ga = new GlideAggregate('incident');

// Group by the 'category' field
ga.groupBy('category');

// Count the number of incidents in each category
ga.addAggregate('COUNT');

// Query the table
ga.query();

// Iterate through the results and display the category and the count
while (ga.next()) {
    var category = ga.getValue('category');
    var count = ga.getAggregate('COUNT');
    
    gs.print('Category: ' + category + ', Count: ' + count);
}

 

 

Result:

AnushaReddyVK_0-1716886937656.png

 

If you find my response helpful, please consider selecting "Accept as Solution" and "Helpful" .

 

Thanks,

Anusha

Ramachandra
Tera Contributor

Thank You @Anusha Reddy VK

 

Ramachandra
Tera Contributor

Hi Anusha Reddy,

Display 10 incidents(number,caller,category) which were created between 1 january 2022 and 1
march 2023 and category is hardware .

guide me Please

var gr = new GlideRecord('incident'); 
gr.addQuery('category', 'hardware'); 
gr.addQuery('sys_created_on', '>=', '2022-01-01 00:00:00'); 
gr.addQuery('sys_created_on', '<=', '2023-03-01 23:59:59'); 
gr.setLimit(10); 
gr.orderByDesc('sys_created_on'); 
gr.query();

while (gr.next()) {
gs.print('Number: ' + gr.getValue('number') +
', Caller: ' + gr.getDisplayValue('caller_id') +
', Category: ' + gr.getValue('category'));
}
}