- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 11:53 PM
Hi Team,
I have written below script in background script the purpose of the script is Group incidents by assigned to and list only grouped records where the assigned to have more than one record. The error i am getting is
invalid return
var agg = new GlideRecord('incident');
agg.addAggregate('COUNT','assigned_to');
agg.query();
var arr =[];
while(agg.next()){
var incidentCount = agg.getAggregate('COUNT','assigned_to');
if(incidentCount >1) {
gs.info('Display the count',[incidentCount])
var inc = new GlideRecord('incident');
inc.addQuery('assigned_to'+agg.assigned_to);
inc.query();
while(inc.next()){
arr.push(inc.sys_id.toString())
}
}
return arr;
gs.print([incidentCount]);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 01:38 AM - edited 05-14-2024 01:49 AM
The code which you have written will not satisfy your requirement, i have modified the entire code ,Please refer the working code as below,
var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT', 'assigned_to');
agg.orderBy('assigned_to');
agg.query();
var incidentCount = 0;
while (agg.next()) {
var num = [];
incidentCount = agg.getAggregate('COUNT', 'assigned_to');
if (incidentCount > 1) {
var gr = new GlideRecord('incident');
gr.addQuery('assigned_to', agg.assigned_to);
gr.query();
while (gr.next()) {
num.push(gr.getValue('number'));
}
gs.info('count for ' + agg.assigned_to.name + ':' + incidentCount + " Incident Numbers : " + num );
}
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 01:38 AM - edited 05-14-2024 01:49 AM
The code which you have written will not satisfy your requirement, i have modified the entire code ,Please refer the working code as below,
var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT', 'assigned_to');
agg.orderBy('assigned_to');
agg.query();
var incidentCount = 0;
while (agg.next()) {
var num = [];
incidentCount = agg.getAggregate('COUNT', 'assigned_to');
if (incidentCount > 1) {
var gr = new GlideRecord('incident');
gr.addQuery('assigned_to', agg.assigned_to);
gr.query();
while (gr.next()) {
num.push(gr.getValue('number'));
}
gs.info('count for ' + agg.assigned_to.name + ':' + incidentCount + " Incident Numbers : " + num );
}
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang