How to capture the SLA breach date for running on incident form

Atik
Tera Contributor

Hi, 

I am working on the Incident management where I have to capture the value of breach time(planned end date) field value,

I am trying with the below code with INC sys_id in background script it is giving the expected result but when using the same code in my Business Rule which is running on the Incident table where I have to capture the value of that field and have to hit other API for integration it is not giving the expected result...

 

var gr = GlideRecord('task_sla');
gr.addEncodedQuery('stage=in_progress^sla.target=resolution');
gr.addQuery('task','f2020ead1bd1f9101bc76280604bcb89');
gr.query();
if(gr.next()){
//obj_custom_field = gr.planned_end_time
gs.print(gr.planned_end_time);
}

 

Please help me with this...

 

 

 

Thanks in advance,

Atik

1 ACCEPTED SOLUTION

kps sumanth
Mega Guru

Hello @Atik ,

I have created a before insert and update business rule to retrieve the same and its returning the expected result, below is the screenshot.

kps2_0-1707994334433.png

 

(function executeRule(current, previous /*null when async*/) {

	var grContract = new GlideRecord('contract_sla');
    var gr = GlideRecord('task_sla');
    gr.addQuery('task', current.sys_id);
    gr.addEncodedQuery('stage=in_progress^sla.target=resolution');
    //gr.addQuery('stage', 'in_progress');
    gr.query();
    if (gr.next()) {
        //obj_custom_field = gr.planned_end_time
        gs.log('BreachDateQuery ' + gr.planned_end_time.getDisplayValue());
    }

})(current, previous);

 

Could you please let me know the exact scenario when you need this value, so that I can help you with the script.

View solution in original post

7 REPLIES 7

kps sumanth
Mega Guru

Hello @Atik ,

 

Could be able to share the code you have written in business rule..?

Atik
Tera Contributor

Hi @kps sumanth ,

below is the code which I had added in my business rule,

 

 var gr = GlideRecord('task_sla');
    gr.addQuery('task', current.sys_id);
    gr.addEncodedQuery('stage=in_progress^grContract.target=resolution');
    //gr.addQuery('stage', 'in_progress');
    gr.query();
    if (gr.next()) {
        //obj_custom_field = gr.planned_end_time
        gs.log('BreachDateQuery ' + gr.planned_end_time.getDisplayValue());
 
Actually, I wanted to capture the Resolution one only not the response one..

kps sumanth
Mega Guru

Hello @Atik ,

 

In line 3 the encoded query is having "grContract.target=resolution", I believe this is coming from sla definition and it should be sla.target=resolution.

 

Could you please let me know the use of this variable in your script "grContract".

Atik
Tera Contributor
 //Breach Date
    var grContract = new GlideRecord('contract_sla');
    var gr = GlideRecord('task_sla');
    gr.addQuery('task', current.sys_id);
    gr.addEncodedQuery('stage=in_progress^sla.target=resolution');
    //gr.addQuery('stage', 'in_progress');
    gr.query();
    if (gr.next()) {
        //obj_custom_field = gr.planned_end_time
        gs.log('BreachDateQuery ' + gr.planned_end_time.getDisplayValue());
    }
actually i got this from community itself I was using this code, In earlier reply i forgot to add first line.. Please suggest me the correct code.
 
Thank,
Atik.