
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2022 05:25 AM
Hi,
My doubt is that once we receive a flood(>100) of incidents in 5 min time then from those incidents can we separate or group incidents based on CI ? and once we sort or group them by CI if there are more than 10 incidents in any groups then for that group can we create a major incident and attach the remaining incidents to the major incident? is there any way in scripting to achieve this? if so please help
Thanks
Datta
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 12:45 AM
Hi,
try this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT', 'cmdb_ci');
agg.addEncodedQuery('sys_created_onRELATIVEGT@minute@ago@60');
agg.addQuery('cmdb_ci', current.cmdb_ci);
agg.query();
while (agg.next()) {
//do things on the results
var incidentCount = agg.getAggregate('COUNT', 'cmdb_ci');
gs.addInfoMessage('Total incidents for this CI ' + incidentCount);
if(incidentCount > 20){
// your logic
}
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 12:08 AM
Hi Ankur,
I have tried after referring to the above link and her below I am pasting my code in that I am able to go inside the group of ci and print the list of Ci but I am unable to fetch if there are 20 records with the same CI, if so from there how can I relate a newly created major incident to those incidents?
var ga = new GlideAggregate('incident');
var count = 0;
var ci =[];
ga.addEncodedQuery('sys_created_onRELATIVEGT@minute@ago@60');
ga.addAggregate('COUNT', 'cmdb_ci');
//gs.info('Total Incident Count ' + ga.getAggregate('COUNT'));
ga.query();
while(ga.next())
{
count = count +1;
ga.setGroup(true);
ga.groupBy('cmdb_ci');
gs.info('CI inside loop ' + ga.cmdb_ci.name + ' ' + ga.getAggregate('COUNT', 'cmdb_ci'));
ci[count] = ga.cmdb_ci;
ci.push();
gs.info('Array' + ci[count]);
}
gs.info('INC Count '+ count);
for (var i = 0; i < count;i++)
{
gs.info('I am inside for loop');
var ga1 = new GlideAggregate('incident');
ga1.addEncodedQuery('sys_created_onRELATIVEGT@minute@ago@60');
//ga1.addAggregate('COUNT', 'cmdb_ci');
ga1.addQuery('cmdb_ci',ci[i]);
ga1.query();
while(ga1.next())
{
gs.info('mission accomplished');
}
}
gs.info('CI' + ga.cmdb_ci.name + ' ' + ga.getAggregate('COUNT', 'cmdb_ci'));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2022 12:45 AM
Hi,
try this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var agg = new GlideAggregate('incident');
agg.addAggregate('COUNT', 'cmdb_ci');
agg.addEncodedQuery('sys_created_onRELATIVEGT@minute@ago@60');
agg.addQuery('cmdb_ci', current.cmdb_ci);
agg.query();
while (agg.next()) {
//do things on the results
var incidentCount = agg.getAggregate('COUNT', 'cmdb_ci');
gs.addInfoMessage('Total incidents for this CI ' + incidentCount);
if(incidentCount > 20){
// your logic
}
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2022 04:33 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader