How to stop SLA without removing setworkflow in BG script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 02:11 AM
Hi Team,
We have a requirement to close bulk incidents through background script.
Script:-
var gr = new GlideRecord('incident');
gr.addQuery('your_criteria_field', 'your_criteria_value');
gr.query();
while (gr.next()) {
gr.setValue('incident_state', '7');
gr.setValue('close_code', 'your_close_code');
gr.setValue('close_notes', 'Your closing notes');
gr.setWorkflow(false);
gr.update();
}
By using this above script. we are able to close the incidents. But still SLA is running. How to stop SLA without removing setworkflow(false).
Kindly please help on this.
Thanks for the advance.
Thanks,
Saikrishna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 02:22 AM
Can't you try gliding in the task_sla table to remove the active SLAs?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2024 02:29 AM
Something like,
var gr = new GlideRecord('incident');
gr.addQuery('your_criteria_field', 'your_criteria_value');
gr.query();
while (gr.next()) {
gr.setValue('incident_state', '7');
gr.setValue('close_code', 'your_close_code');
gr.setValue('close_notes', 'Your closing notes');
gr.setWorkflow(false);
gr.update();
var grSLA=new GlideRecord('task_sla');
grSLA.addEncodedQuery('task.sys_id='+gr.sys_id.toString())
grSLA.query();
grSLA.deleteMultiple();
}
NB: Verify the syntax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2024 08:25 PM
I have tried above script but all activities are triggering. And state is inprogress.
Please find below screenshots.
Please help on this.
Thanks,
Saikrishna
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 06:50 AM
I assume that the backend value for 'state' is just 'state NOT 'incident_state'.
Try this instead.
var gr = new GlideRecord('incident');
gr.addQuery('your_criteria_field', 'your_criteria_value');
gr.query();
while (gr.next()) {
gr.setValue('state', 7);
gr.setValue('close_code', 'your_close_code'); //Use a valid close code from the choices available
gr.setValue('close_notes', 'Your closing notes');
gr.setWorkflow(false);
gr.update();
var grSLA=new GlideRecord('task_sla');
grSLA.addEncodedQuery('task.sys_id='+gr.sys_id.toString())
grSLA.query();
grSLA.deleteMultiple();
}
Please mark 👍if you find this helpful.