- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 01:30 AM
I want to fetch the all the "In_Progress" incidents and finally change the state to "Closed", how can i achieve this ?
Using Background script (Other way would also appreciated).
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 01:37 AM
Hi @Parth_S ,
You can do it via fix script or background script, but do it in lower instance.
As per businesses usecases will not close the bulk inprogress incidents to closed.
var updatedCount = 0;
var grIncident = new GlideRecord('incident');
grIncident.addQuery('state', 2);
grIncident.setLimit(10)
grIncident.query();
while (grIncident.next()) {
// Disable business rules and workflows
grIncident.setWorkflow(false);
grIncident.state = 7
grIncident.update();
updatedCount++;
}
gs.print(updatedCount + " incidents updated to Closed.");
If my response helped, please mark it as the accepted solution ✅ and give a thumbs up👍.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 01:39 AM - edited 12-11-2024 01:42 AM
Hello @Parth_S ,
You can run below background script.
// Create a GlideRecord object for the 'incident' table
var gr = new GlideRecord('incident');
// Query for incidents where the state is "In Progress" (assuming "In Progress" state is a value in the state field)
gr.addQuery('state', 2);
gr.query();
while (gr.next()) {
gr.state = '7'; // Set the state to "Closed"
gr.update(); // Update the record in the database
}
gs.info('All "In Progress" incidents have been closed.');
Thanks,
Valmik Patil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 01:37 AM
Hi @Parth_S ,
You can do it via fix script or background script, but do it in lower instance.
As per businesses usecases will not close the bulk inprogress incidents to closed.
var updatedCount = 0;
var grIncident = new GlideRecord('incident');
grIncident.addQuery('state', 2);
grIncident.setLimit(10)
grIncident.query();
while (grIncident.next()) {
// Disable business rules and workflows
grIncident.setWorkflow(false);
grIncident.state = 7
grIncident.update();
updatedCount++;
}
gs.print(updatedCount + " incidents updated to Closed.");
If my response helped, please mark it as the accepted solution ✅ and give a thumbs up👍.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 01:37 AM
What is your business case to do this?
What is the logic you need to run on this (or not run on this)?
Closing incidents will trigger notifications and doing it by script will not set close notes/close codes or provide the user with any update on the incident they have created.
Be really careful with these kinds of requirements. But if it's legit:
var grInc = new GlideRecord('incident');
grInc.addEncodedQuery('add_your_incoded_query_here'; // could be as simple as 'state=2'
grInc.query();
while(grInc.next()){
grInc.setValue('state','7'); // closed
grInc.work_notes = 'Closed via script because .......';
grInc.add other fields you need updated like close notes/code/etc
//grInc.setWorkflow(false); // if you don't want to trigger anything
grInc.update();
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 01:39 AM - edited 12-11-2024 01:42 AM
Hello @Parth_S ,
You can run below background script.
// Create a GlideRecord object for the 'incident' table
var gr = new GlideRecord('incident');
// Query for incidents where the state is "In Progress" (assuming "In Progress" state is a value in the state field)
gr.addQuery('state', 2);
gr.query();
while (gr.next()) {
gr.state = '7'; // Set the state to "Closed"
gr.update(); // Update the record in the database
}
gs.info('All "In Progress" incidents have been closed.');
Thanks,
Valmik Patil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2024 01:41 AM - edited 12-11-2024 01:42 AM
Hello @Parth_S ,
You can run below code in the background script or you can create fix script and below code and run fix script.
var incident = new GlideRecord('incident');
incident.addQuery('state', '2');
incident.query();
while(incident.next()){
incident.state = '7';
incident.close_code = 'Duplicate'; // add resolution code
incident.close_notes = 'incident has been closed'; // add resolution note
incident.update();
}