Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to supress notification on Incident

Akshaykhare
Tera Contributor

I want to cancel the incident in bulk but notification should not trigger to the assignment group for this process. I am using following script to cancel the INC.

 

var gr = new GlideRecord('incident'); gr.addEncodedQuery("numberININC0535119");
 
 gr.query();
 
 while(gr.next()) {
 gr.state='8';

gr.assignment_group = "874500c8db99af001ce298f3db9619e3";
gr.assigned_to = "12665d45dbacd300ebd7f3361d9619fe";
gr.business_service = "ef19a128dba86b003700ff361d961966";
gr.work_notes="Canceling the change as per ----------";
 
gr.autoSysFields(false);

gr.setWorkflow(false);
gr.update();


}
 
In this script I am using the line gr.setWorkflow(false) which supress the notification but due to this line SLA is not getting cancled and if I comment out this line SLA is getting cancelled but notification are also getting triggered
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Akshaykhare 

set it cancel via script

var gr = new GlideRecord('incident');
gr.addEncodedQuery("numberININC0535119");
gr.query();
while(gr.next()) {
    gr.state = '8';
    gr.assignment_group = "874500c8db99af001ce298f3db9619e3";
    gr.assigned_to = "12665d45dbacd300ebd7f3361d9619fe";
    gr.business_service = "ef19a128dba86b003700ff361d961966";
    gr.work_notes = "Canceling the change as per ----------";
    
    gr.autoSysFields(false);
    gr.setWorkflow(false);
    gr.update();
    // Manually stop SLAs
    var slaGR = new GlideRecord('task_sla');
    slaGR.addQuery('task', gr.sys_id);
    slaGR.query();
    while (slaGR.next()) {
        slaGR.setValue('stage', 'cancelled'); // cancel SLA
        slaGR.update();
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Ankur Bawiskar
Tera Patron
Tera Patron

@Akshaykhare 

set it cancel via script

var gr = new GlideRecord('incident');
gr.addEncodedQuery("numberININC0535119");
gr.query();
while(gr.next()) {
    gr.state = '8';
    gr.assignment_group = "874500c8db99af001ce298f3db9619e3";
    gr.assigned_to = "12665d45dbacd300ebd7f3361d9619fe";
    gr.business_service = "ef19a128dba86b003700ff361d961966";
    gr.work_notes = "Canceling the change as per ----------";
    
    gr.autoSysFields(false);
    gr.setWorkflow(false);
    gr.update();
    // Manually stop SLAs
    var slaGR = new GlideRecord('task_sla');
    slaGR.addQuery('task', gr.sys_id);
    slaGR.query();
    while (slaGR.next()) {
        slaGR.setValue('stage', 'cancelled'); // cancel SLA
        slaGR.update();
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar : This solution is setting the stage of SLA to cancelled but SLA clock is still running. Any solution for this?

@Akshaykhare 

are you saying the sla timer is still running?

try to set the stop time field (end_time) with the current date/time and see

var slaGR = new GlideRecord('task_sla');
    slaGR.addQuery('task', gr.sys_id);
    slaGR.query();
    while (slaGR.next()) {
        slaGR.setValue('stage', 'cancelled'); // cancel SLA
        slaGR.setValue('end_time', new GlideDateTime());
        slaGR.update();
    }

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar : I tried doing the same but again stop time(end_time) got mapped with the current date and time but SLA timer is still running.

 

SLA timer is getting stopped only when I don't use the line gr.setWorkflow(false) but then it triggers notification as well.