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

Shivalika
Mega Sage

Hello @damodharan1  

 

I have done same for incident in my instance using the code below. Refer the attached screenshot :- 

 

var gr = new GlideRecord('incident');
gr.addQuery('number','INC0865942');
gr.query();
var duration = 0;
if(gr.next())
{
    var ot = new GlideDateTime(gr.sys_created_on);
    var ct = new GlideDateTime(gr.closed_at);
    duration = GlideDateTime.subtract(ot,ct);
    gr.setValue('business_duration',duration);
    gr.update();
   
}
gs.print(duration.getDisplayValue());
 
Shivalika_0-1742994727110.png

 

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

 

Hi @Shivalika 
  Thanks for the quick response. The above code is working but its not taking business hours from calendar. So both duration & business duration fields are having same value.

Hello @damodharan1 

 

Please use below script :- 

var result = 0,
    count = 0,
    opened, resolved;


var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0815419');
gr.query();
if (gr.next()) {
opened = gr.opened_at;
resolved = gr.resolved_at;
gs.print(gr.number + " " + opened + " " + resolved);
result = gs.calDateDiff(opened, resolved, false);
gs.print(gr.number + " " + result);
   //gr.business_duration=result;
//gr.setWorkflow(false);
//gr.update();

}
 
Even I tried this and I am also getting a different value now.

Shivalika_0-1742999285316.png

 

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


Hi @Shivalika 
     Yes i tried but its not returning any value for business duration field.  

Screenshot 2025-03-26 202428.png

 

Screenshot 2025-03-26 202209.png