- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 02:19 AM
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();
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 02:22 AM
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
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 02:20 AM
Replace
gr.addEncodedQuery('assignment_group'=287ebd7da9fe198100f92cc8d1d2154e^'state'=1);
with
gr.addEncodedQuery('assignment_group=287ebd7da9fe198100f92cc8d1d2154e^state=1');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 02:22 AM
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
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 02:28 AM - edited 11-01-2023 02:30 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 02:29 AM
Also, please note that,
"Resolution Code" and "Resolution Notes" are mandatory fields on the Incident form whenever you are closing an incident.