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 ,

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.

Atik
Tera Contributor

Actually, there is E-bonding(ServiceNow to ServiceNow), where integration with Incident Management, Based on the specific Assignment Groups Integration will trigger.

So, we are sending all the fields values, here I have a requirement that i need to send the Breach date field value to the other instance and other instance is managing by some XYZ team wanted that field value and based on that they will manage there SLA..

 

So I have to send the Breach date for SLA in progress, resolution one... 

kps sumanth
Mega Guru

Hello @Atik ,

 

The above business rule should work in retrieving the end time value just you need to add the assignment group condition. Could you please let me know the log message you are getting. It would be helpful if you can share the complete code to debug.