How to stop SLA without removing setworkflow in BG script

thaduri sai
Tera Contributor

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

 

5 REPLIES 5

Abhijith322
Tera Contributor

Can't you try gliding in the task_sla table to remove the active SLAs?

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

I have tried above script but all activities are triggering. And state is inprogress.

 

Please find below screenshots.

1000064949.jpg

1000064948.jpg

Please help on this.

 

Thanks,

Saikrishna

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.