
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 03:47 AM
Hi, My use case is that when there are 200 tickets with the same Location I need to create one Major Incident and attach all these 200 tickets as Child Incidents to this newly created Major Incident.
I have tried the below code but the problem I am facing is that more than 20 Major incidents are getting created when I run this code and also I am not getting any Logic on how to link those 200 tickets to this new Major incident.
After BR with Insert and Update:
(function executeRule(current, previous /*null when async*/ ) {
var ga = new GlideAggregate("incident");
ga.addQuery("location", current.location);
ga.addQuery("state", "<", "6");
ga.addQuery("major_incident_state","=","");
ga.addAggregate("COUNT");
ga.query();
while (ga.next()) {
var count = ga.getAggregate("COUNT");
}
gs.log("MLD Count" + count);
if(count > 5) {
var gr = new GlideRecord("incident");
gr.initialize();
gr.major_incident_state = "Accepted";
gr.short_description = "Major incident is created for 5 tickets with location :" + current.location;
gr.caller_id = "6816f79cc0a8016401c5a33be04be441";
gr.insert();
}
})(current, previous);
*for now I am comparing it with 5 and also MI should copy as many fields it can from latest created incident\
Kindly help me with this Use case
Thanks,
M Lohith Datta
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 04:13 AM
OR you can try below code
var majInSys = "nothing";
var gaInc = new GlideAggregate('incident');
gaInc.addActiveQuery();
gaInc.addQuery('location', current.location);
gaInc.addAggregate('COUNT');
gaInc.orderByDesc('created');
gaInc.query();
if (gaInc.next()){
var count = gaInc.getAggregate('COUNT');
if (count == 200){
var gr = new GlideRecord("incident");
gr.initialize();
gr.major_incident_state = "Accepted";
gr.short_description = "Major incident is created for 5 tickets with location :" + current.location;
gr.caller_id = "6816f79cc0a8016401c5a33be04be441";
gr.field = gaInc.field;
gr.field = gaInc.field;
gr.field = gaInc.field;
majInSys = gr.insert();
}
}
if (majInSys != "nothing"){
var grIncU = new GlideRecord('incident');
grIncU.addActiveQuery();
grIncU.addQuery('location',current.location);
grIncU.query();
while (grIncU.next()){
grIncU.parent = majInSys;
grIncU.setWorkflow(false);
grIncU.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 03:55 AM
Hi Lohith,
Why not create a field in location record which stores integer like number_of_incidents.
Whenver an Incident is created, update its location record with number_of_incidents = number_of_incidents +1.
Whenver an Incident is closed , update its location record with number_of_incidents = number_of_incidents - 1.
Write a BR in location table which runs whenver number_of_incident changes. If the count is 200. Create a major incident. Capture its sys_id.
Then GlideRecord the incident table, and query all active incidents having that location. update their parent field with sys_id of the major incident.
This is a very simplified process.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 04:15 AM
Hi Suvro,
Thanks for the simplified explanation but in my case, I want to proceed without creating any new fields and also I wanna know why my above code is not working properly.
Thanks,
Datta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 04:29 AM
replace while with if only one major incident will be created. Plus I have shared the whole code with you. You can compare and implement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2022 04:13 AM
OR you can try below code
var majInSys = "nothing";
var gaInc = new GlideAggregate('incident');
gaInc.addActiveQuery();
gaInc.addQuery('location', current.location);
gaInc.addAggregate('COUNT');
gaInc.orderByDesc('created');
gaInc.query();
if (gaInc.next()){
var count = gaInc.getAggregate('COUNT');
if (count == 200){
var gr = new GlideRecord("incident");
gr.initialize();
gr.major_incident_state = "Accepted";
gr.short_description = "Major incident is created for 5 tickets with location :" + current.location;
gr.caller_id = "6816f79cc0a8016401c5a33be04be441";
gr.field = gaInc.field;
gr.field = gaInc.field;
gr.field = gaInc.field;
majInSys = gr.insert();
}
}
if (majInSys != "nothing"){
var grIncU = new GlideRecord('incident');
grIncU.addActiveQuery();
grIncU.addQuery('location',current.location);
grIncU.query();
while (grIncU.next()){
grIncU.parent = majInSys;
grIncU.setWorkflow(false);
grIncU.update();
}
}