Calculate duration on incident based on Outage related list

AndersBGS
Tera Patron
Tera Patron

Hi all, 

 

Can anybody please help on how to calculate duration between field on the incident form and field on the outage form? Incident.created subtracted from CMDB_CI_Outage.begin. 

 

The outage record is listed in the outage related list on the incident form.

I guess i should utilize a function like "function getTimeDiff(){ "

 

Please let me have your suggestion how to do this best possible. 

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

1 ACCEPTED SOLUTION

Yes, then we just turn the script around, so we look up the incident instead of the outage! See updated script below

 

var outStart = current.sys_created_on.getDisplayValue(); // Outage begin
var incId = current.getValue('task_number'); //we get the incident
var incBegin = '';

//Here we query the incident that is related to the incident above. 
var incGr = new GlideRecord('incident');
incGr.addQuery('sys_id', incId);
incGr.query();
if(incGr.next()) {
incBegin = incGr.begin.getDisplayValue();
}
if(incBegin) { //Let's be sure that we found an incident
//We save the duration from incident begin (incBegin) to outage start (outStart) in the value duration.. 
var duration = gs.calDateDiff(incBegin, outStart , false); 
current.u_outage_incident_created = duration; 
}

 

Since the outage is linked to a task, then I would only have the  business rule on insert. Also make sure that it has a "task_number is not empty" in the condition! 🙂 


Best regards,
Sebastian Laursen

View solution in original post

7 REPLIES 7

Yes, then we just turn the script around, so we look up the incident instead of the outage! See updated script below

 

var outStart = current.sys_created_on.getDisplayValue(); // Outage begin
var incId = current.getValue('task_number'); //we get the incident
var incBegin = '';

//Here we query the incident that is related to the incident above. 
var incGr = new GlideRecord('incident');
incGr.addQuery('sys_id', incId);
incGr.query();
if(incGr.next()) {
incBegin = incGr.begin.getDisplayValue();
}
if(incBegin) { //Let's be sure that we found an incident
//We save the duration from incident begin (incBegin) to outage start (outStart) in the value duration.. 
var duration = gs.calDateDiff(incBegin, outStart , false); 
current.u_outage_incident_created = duration; 
}

 

Since the outage is linked to a task, then I would only have the  business rule on insert. Also make sure that it has a "task_number is not empty" in the condition! 🙂 


Best regards,
Sebastian Laursen

Hi Sebastian,

 

Worked like a charm - only had to change the order of the business rules, due to out of the box rule "Outage Calculations" conflicted with the new business rule.

 

Thanks again so much for your assistance - I have accepted your solution 🙂

 

/Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Hi Anders,

 

So glad it worked!


Best regards,
Sebastian Laursen