Background script to resolve the incident and update the state of all attached sla to complete.

Mohd Daud Khan
Tera Contributor

Hi ,

 

I want to write a background script for mass closure of incident and the attached sla's.

Condition: To update the 
Assignment Group(which I am not part of)
Assigned To

Service Offering

Close code


I wrote the below script but the sla's are not getting completed.

 

var incident = new GlideRecord("incident");
//incident.addEncodedQuery('numberINC0447123');
incident.addQuery('number', 'INC0447175');
incident.query();
while(incident.next()) {
var inc= new GlideRecord("task_sla");
inc.addQuery('task','INC0447175');
inc.query();
while(inc.next()) {
//inc.setWorkflow(false);
//inc.autoSysFields(false);
inc.stage='completed';
inc.update();
}
incident.service_offering='870f7d3d4fddeb804c89d48e5210c7ff';
incident.business_service='Enterprise Logistics';
incident.assignment_group='9fae169b4fab0a40ec33d0af0310c752';
incident.assigned_to='13209bdb13276e0025ec38b2f244b0d6';
incident.comments='Closing ticket';
incident.close_notes='Closing ticket';
incident.close_code='Solved (Permanently)';
incident.state=6;
incident.autoSysFields(false);
incident.setWorkflow(false);
incident.update();
}

1 REPLY 1

Ratnakar7
Mega Sage
Mega Sage

Hi @Mohd Daud Khan ,

 

Here's the modified script:

var incident = new GlideRecord("incident");
//incident.addEncodedQuery('numberINC0447123');
incident.addQuery('number', 'INC0447175');
incident.query();
while (incident.next()) {
  var inc = new GlideRecord("task_sla");
  inc.addQuery('task', incident.sys_id); // Use the sys_id of the incident to filter SLAs
  inc.query();
  while (inc.next()) {
    //inc.setWorkflow(false);
    //inc.autoSysFields(false);
    inc.stage = 'completed';
    inc.update();
  }
  incident.service_offering = '870f7d3d4fddeb804c89d48e5210c7ff';
  incident.business_service = 'Enterprise Logistics';
  incident.assignment_group = '9fae169b4fab0a40ec33d0af0310c752';
  incident.assigned_to = '13209bdb13276e0025ec38b2f244b0d6';
  incident.comments = 'Closing ticket';
  incident.close_notes = 'Closing ticket';
  incident.close_code = 'Solved (Permanently)';
  incident.state = 6;
  incident.autoSysFields(false);
  incident.setWorkflow(false);
  incident.update();
}

 

Thanks,

Ratnakar