Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to auto Resolve Incidents that are 30 days or older

velvet
Mega Guru

find_real_file.pngfind_real_file.png

1 ACCEPTED SOLUTION

Create a scheduled job: 

find_real_file.png

 

Create a script include:find_real_file.pngBelow is the code from the screenshots:

Scheduled Job:

new closeIncidents().close();

Script Include: 

 

var closeIncidents = Class.create();
closeIncidents.prototype = {
    initialize: function() {
    },
	
	close: function() {
		var incidents = new GlideRecord("incident");
		incidents.addEncodedQuery("active=true^sys_created_on<=javascript:gs.beginningOfLast30Days()");
		incidents.query();
		while(incidents.next()) {
			incidents.state = 6;
			incidents.update(); 
		}
	},

    type: 'closeIncidents'
};

 

Please mark this as correct/helpful if it resolved your issue!

View solution in original post

6 REPLIES 6

Elijah Aromola
Mega Sage

Business rules only run on insert/update of a record. You need to convert this business rule into a scheduled job that runs once a day at a specified time (or whenever you want). 

 

If this resolved your issue please mark as helpful/correct!

I am not good at scripting can you help

 

 

 

find_real_file.png

Create a scheduled job: 

find_real_file.png

 

Create a script include:find_real_file.pngBelow is the code from the screenshots:

Scheduled Job:

new closeIncidents().close();

Script Include: 

 

var closeIncidents = Class.create();
closeIncidents.prototype = {
    initialize: function() {
    },
	
	close: function() {
		var incidents = new GlideRecord("incident");
		incidents.addEncodedQuery("active=true^sys_created_on<=javascript:gs.beginningOfLast30Days()");
		incidents.query();
		while(incidents.next()) {
			incidents.state = 6;
			incidents.update(); 
		}
	},

    type: 'closeIncidents'
};

 

Please mark this as correct/helpful if it resolved your issue!

 I don't want to Close them, I want to Resolve them.. So do I just change where you have Close put Resolved?