How to set Business Duration field on RITM?

damodharan1
Tera Contributor

I'm not able to set business duration field on old ritms and i have used below codes.
var grRITM = new GlideRecord('sc_req_item');
grRITM.addEncodedQuery("number=RITM18884753^business_duration=javascript:gs.getDurationDate('0 0:0:0')");
grRITM.query();

if (grRITM.next()) {
var opened = grRITM.opened_at.getValue();
var closed = grRITM.closed_at.getValue();

if (grRITM.business_duration == '') {
grRITM.business_duration = gs.calDateDiff(opened, closed, false);
grRITM.update();
}
}


Is there any alternative method for calDateDiff.

16 REPLIES 16

Hello @damodharan1 

 

Please take another incident as example, because see the opened timing and resolved timing is completely same it's hardly 20 seconds difference - so what would the business duration be ? 

 

The business duration field only stores values in days, Hours and minutes not seconds. 

 

Please try on an existing incident, don't create a new incident and resolve it. I am sure this will work, refer my screenshot, it's live example. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Hello Shivalika
    Even for other incidents it was same result and not sure why its not working.

Regards,
Damodharan

Screenshot 2025-03-26 204759.png

 

Hello @damodharan1 

 

I am not understanding why are you taking incidents which have barely few seconds to few minutes of difference ? In that time - business duration - how will it calculate - what if it wasn't even in the business days?

 

please check on your table with incidents which are having some nice difference like I showed it gave me 5 Days and Few hours and minutes. Select some nice incidents and check this. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway. This will help me be recognized for the efforts and also move this questions from unsolved to solved bucket. 

 

Regards,

 

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

@damodharan1 

you want to find difference between opened and closed using some schedule?

if yes then which schedule it is? your script didn't mention anything about schedule

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Shree_G
Kilo Sage

Hello @damodharan1 

 

I can see the wrong format used to get the Values. Use below to correct :

 

var opened = grRITM.getValue('opened_at');
var closed = grRITM.getValue('closed_at');
 
In terms of Calculations for Date consider using GlideDateTime API to convert.

If this solution helped resolve your issue, please consider marking it as helpful or correct.
This will assist others in finding the solution faster and close the thread.