how to create SLA has breached by script

devservicenow k
Tera Contributor

MY requirement is in SLA using Workflow.

i am creating an sn_customerservice_task

. when ever sn_customerservice_task is created SLA should run for 24 hours.

if the SLA has breached , the  notification should be sent.

i have created an code to check the task is breached , but it is not working

answer = ifScript();
var gr = new GlideRecord('task_sla');
gr.addQuery('task', sys_id);
gr.addQuery('has_breached', true);
gr.query();
   function ifScript() {
    if (gr.sla.type == 'sn_customerservice_task') {
       return 'yes';
      }
      return 'no';
         }

send me the updated script

11 REPLIES 11

suvro
Mega Sage
Mega Sage

Have you tried to check Default SLA workflow ? There you have activity to notify after breach.

 

As far as your code is concerned. Assuming that you are running the workflow on sn_customerservice_task table modified script below

answer = ifScript();

function ifScript() {
var gr = new GlideRecord('task_sla');
gr.addQuery('task', current.sys_id); //Giving only sys_id will not work depending on which table wf is running use the sys_id
gr.addQuery('has_breached', true);
gr.query();

if (gr.next()){
   
    if (gr.sla.type == 'sn_customerservice_task') {
       return 'yes';
      }
      return 'no';
         }

}

i am doing the workflow in interaction table. but i need to do the query from case table , so how to do that in script guide me script 

answer = ifScript();
var acc =new GlideRecord('sn_customerservice_case');
var gr = new GlideRecord('task_sla');
gr.addQuery('task', acc.sys_id);
gr.addQuery('has_breached', true);
gr.query();
   function ifScript() {
    if (gr.sla.type == 'sn_customerservice_task') {
       return 'yes';
      }
      return 'no';
         }

 

is this correct?

Why are you running this query in the same workflow? 

Just run it on the task_sla table (or even in the existing sla workflow). Trigger an event and send the email.

If my answer helped you in any way, please then mark it as helpful.

Mark


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark