I'm trying to check if an incident has breached SLA and the type is an SLA

peekay19
Tera Contributor

The task_sla table has both the fields that I need:
- a boolean field "has_breached" which gives me the confirmation if the ticket has breached SLA.
- a reference field "sla"(table: contract_sla) which gives me either an SLA, or an OLA, or an Underpinning Contract
The code below gives me both the has breached value and the SLA type when I run it in the Background Script.

var gr = new GlideRecord('task_sla');
gr.addQuery('task', sys_id);
gr.addQuery('has_breached', true);
gr.query();
while(gr.next()){
if (gr.sla.type == 'SLA'){
gs.addInfoMessage("the SLA type is: " + gr.sla.type)
}
}

However, when I run the same code in a Script Include or as a callback function in a client script the SLA type produces an "undefine" value
Script Include:
var GetSLATypeAJAX = Class.create();
GetSLATypeAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSLAInfo : function(){
var sys_id = this.getParameter('sysparm_sys_id');

var gr = new GlideRecord('task_sla');
gr.addQuery('task', sys_id);
gr.addQuery('has_breached', true);
gr.query();
while(gr.next()){
if (gr.sla.type == 'SLA'){
return true;
}
}
},

type: 'GetSLATypeAJAX'
});
This is not working because gr.sla.type is "undefine"

1 ACCEPTED SOLUTION

AirSquire
Tera Guru

Inside while loop log the sys_id and sla.type. If logged, check what values are you receiving.

getSLAInfo : function(){
var sys_id = this.getParameter('sysparm_sys_id'); 

var gr = new GlideRecord('task_sla');
gr.addQuery('task', sys_id);
gr.addQuery('has_breached', true);
gr.query();
while(gr.next()){
gs.log('Sys id received '+sys_id);
gs.log('This is the type of sla '+gr.sla.type)
if (gr.sla.type == 'SLA'){
return true;
}
} 
},

Regards
Air

View solution in original post

1 REPLY 1

AirSquire
Tera Guru

Inside while loop log the sys_id and sla.type. If logged, check what values are you receiving.

getSLAInfo : function(){
var sys_id = this.getParameter('sysparm_sys_id'); 

var gr = new GlideRecord('task_sla');
gr.addQuery('task', sys_id);
gr.addQuery('has_breached', true);
gr.query();
while(gr.next()){
gs.log('Sys id received '+sys_id);
gs.log('This is the type of sla '+gr.sla.type)
if (gr.sla.type == 'SLA'){
return true;
}
} 
},

Regards
Air