Create incident when no incident is created in last 15 minutes by integration user

rakshith_shetty
Tera Contributor

Hi team

 

i would like to create a new incident when there is no incident created in last 15 minutes time

To be specific, we have integrated monitoring tools with ServiceNow for ticketing and an integration user will create an incident when there is a critical/major/minor/warning alerts received. But there was an instance where incidents were not created more than 3 hours due to which missed most critical alerts and lead to business impacts.

 

So I would like to minimize this by enabling proactive creating new incidents and assigning it to service desk if no incidents created in last 15 mins 

 

For this requirement i have created scheduled job and schedule job is running for every 15 mins, i have to create the incident only when no incident is created in last 15 minutes, but below code is not working fine it is creating incidents for every 15 mins , can someone assist me on this issue ?

 

var incidentGR = new GlideRecord('incident');
   
    incidentGR.addEncodedQuery('opened_by=f384ab318787fd1008d4fcc7dabb35d7^sys_created_onRELATIVELT@minute@ago@15');
 
 
       incidentGR.query();
 
    if (!incidentGR.next()) {
        // No incident found in the past 15 minutes, create incident
  
        // creating an incident
        var newIncident = new GlideRecord('incident');
        newIncident.initialize();
        newIncident.caller_id = '';
newIncident.opened_by = '';
        newIncident.contact_type = 'Event Monitoring';
        newIncident.short_description = 'heartbeat monitoring';
        newIncident.assignment_group = '0fb2a6051b849e10ab18c8415b4bcbc7';
        newIncident.category = 'Software';
        newIncident.subcategory = 'Application';
        newIncident.impact = '1'; 
        newIncident.urgency = '4'; 
newIncident.business_service = '';
newIncident.service_offering='';
        newIncident.cmdb_ci = '';
        newIncident.description = 'heartbeat monitoring ' + new GlideDateTime().toString();
        newIncident.insert();
    }
})();

 

 

1 ACCEPTED SOLUTION

Abhishek_Thakur
Mega Sage

Hello @rakshith_shetty ,

Please use the below script, I tried it in my PDI it is creating an incident hopefully it will work for you as well.

var incidentGR = new GlideRecord('incident');
    incidentGR.addEncodedQuery('opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^sys_created_onRELATIVEGT@minute@ago@15');  // change the sys_id of user;
	incidentGR.query();
   if (!incidentGR.next()) {
        // No incident found in the past 15 minutes, create incident
  
        // creating an incident
        var newIncident = new GlideRecord('incident');
        newIncident.initialize();
        newIncident.caller_id = '';
newIncident.opened_by = '';
        newIncident.contact_type = 'Event Monitoring';
        newIncident.short_description = 'heartbeat monitoring';
        newIncident.assignment_group = '0fb2a6051b849e10ab18c8415b4bcbc7';
        newIncident.category = 'Software';
        newIncident.subcategory = 'Application';
        newIncident.impact = '1'; 
        newIncident.urgency = '4'; 
newIncident.business_service = '';
newIncident.service_offering='';
        newIncident.cmdb_ci = '';
        newIncident.description = 'heartbeat monitoring ' + new GlideDateTime().toString();
    }
	newIncident.insert();

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.

View solution in original post

2 REPLIES 2

Abhishek_Thakur
Mega Sage

Hello @rakshith_shetty ,

Please use the below script, I tried it in my PDI it is creating an incident hopefully it will work for you as well.

var incidentGR = new GlideRecord('incident');
    incidentGR.addEncodedQuery('opened_byDYNAMIC90d1921e5f510100a9ad2572f2b477fe^sys_created_onRELATIVEGT@minute@ago@15');  // change the sys_id of user;
	incidentGR.query();
   if (!incidentGR.next()) {
        // No incident found in the past 15 minutes, create incident
  
        // creating an incident
        var newIncident = new GlideRecord('incident');
        newIncident.initialize();
        newIncident.caller_id = '';
newIncident.opened_by = '';
        newIncident.contact_type = 'Event Monitoring';
        newIncident.short_description = 'heartbeat monitoring';
        newIncident.assignment_group = '0fb2a6051b849e10ab18c8415b4bcbc7';
        newIncident.category = 'Software';
        newIncident.subcategory = 'Application';
        newIncident.impact = '1'; 
        newIncident.urgency = '4'; 
newIncident.business_service = '';
newIncident.service_offering='';
        newIncident.cmdb_ci = '';
        newIncident.description = 'heartbeat monitoring ' + new GlideDateTime().toString();
    }
	newIncident.insert();

 

Please mark my answer as accepted solution and give thumbs up, if it helps you.

Abhishek_Thakur
Mega Sage

Hello @rakshith_shetty ,

If my response helped you, could you please accept my answer so it will help other also.