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.

close the incident when state is new

pvv1045330
Tera Contributor

Hi All,

 

I need a one help, we need to close the all incidents/incident tasks with assignment is software group and state is new.

Have write a background script but it's not working .

 

var gr = new GlideRecord('incident');
gr.addEncodedQuery('assignment_group'=287ebd7da9fe198100f92cc8d1d2154e^'state'=1);
gr.query();
while(gr.next()){
gr.state= 7;
gr.update();
}

 

 

1 ACCEPTED SOLUTION

Also, better is to always log things before executing. So, try below

var gr = new GlideRecord('incident');
gr.addEncodedQuery('assignment_group=287ebd7da9fe198100f92cc8d1d2154e^state=1');
gr.query();
gs.print(gr.getRowCount());//this will give number of records
while(gr.next()){
gr.state= 7;
//gr.update(); //if the count is correct you can uncomment this line of code
}

View solution in original post

4 REPLIES 4

Jaspal Singh
Mega Patron
Mega Patron

Replace

gr.addEncodedQuery('assignment_group'=287ebd7da9fe198100f92cc8d1d2154e^'state'=1);

with

gr.addEncodedQuery('assignment_group=287ebd7da9fe198100f92cc8d1d2154e^state=1');

Also, better is to always log things before executing. So, try below

var gr = new GlideRecord('incident');
gr.addEncodedQuery('assignment_group=287ebd7da9fe198100f92cc8d1d2154e^state=1');
gr.query();
gs.print(gr.getRowCount());//this will give number of records
while(gr.next()){
gr.state= 7;
//gr.update(); //if the count is correct you can uncomment this line of code
}

Aniket Bhanse
Tera Guru

Please update your code to be this:

 

var gr = new GlideRecord('incident');
//gr.addEncodedQuery('assignment_group'=287ebd7da9fe198100f92cc8d1d2154e^'state'=1);
gr.addEncodedQuery("assignment_group=287ebd7da9fe198100f92cc8d1d2154e^state=1")
gr.query();
while(gr.next()){

//gs.info(gr.getRowCount());
gr.state = 7;
gr.update();
}

 

 

Aniket Bhanse
Tera Guru

Also, please note that,

 

"Resolution Code" and "Resolution Notes" are mandatory fields on the Incident form whenever you are closing an incident.