Need help in the scripting to display the array values while using GlideAggregate

Maradani Revat1
Tera Contributor

Hi,

We are using Glide Aggregate and trying to display the values of the incident number in an array as output but we are not able to display the values. If you use GlideRecord we are able to display the value and the below script is working for GlideRecord but not for Glide Aggregate. Can anyone please help us with the issue.

 

var score='';
var scoreJson=[];
var scanApp = new GlideAggregate('incident'); // if we use Glide Record below script is working
scanApp.addEncodedQuery("state!=7^short_description!=NULL");
scanApp.groupBy('sys_created_by');
scanApp.orderByDesc('sys_created_on');
scanApp.getRowCount();
scanApp.query();

 

gs.info(scanApp.getRowCount());

 


      while(scanApp.next()){
        
        score=scanApp.getDisplayValue("number");

 

 

         scoreJson.push(score.toString());

 

}

 

 

          gs.info(scoreJson);

 

Output - while using Glide Aggregate -

find_real_file.png

Output while using Glide Record

 

find_real_file.png

 

 

7 REPLIES 7

Sagar Pagar
Tera Patron

Hi,

As suggested by Vaibhav, update the groupBy to number field or comment the below lines

scanApp.groupBy('sys_created_by');
scanApp.orderByDesc('sys_created_on');

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hi Sagar,

I want to group them by sys_created_user as each user may create multiple incidents. So I want to get only the latest incident created by each user.

 

Thanks,

Revathi

Maradani Revat1
Tera Contributor

hi @Sagar Pagar ,

 

find_real_file.png

If you see the above screenshot. I need to print INC0000037,INC0000031 ..... so on numbers for each user.