Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Duration field on RITM

jeevitha3
Kilo Contributor

Hi All,

I need duration of RITM by OOB, When i resolve incident , I am getting duration field auto populated but for RITM when I close complete, duration field is not auto populated. Is there any way to achieve this by OOB without any customizations. Please find screenshots below,

Incident:

find_real_file.png

RITM:

find_real_file.png

Thanks in Advance

2 REPLIES 2

madanm7786
Mega Guru

Hi Jeevitha,



In incident this field is populated from OOB BR mark_resolved.


Create a new BR in requested item table and copy the piece of code from OOB BR.




Thanks,


Maddy


larstange
Mega Sage

Hi



The duration field (calendar_duration) is set by a business rule called "mark_resolved".   There are one defined for both incident and problem.


You need to make a copy if one if these an implemented it for the sc_req_item table.



Alternatively you can create a metric to calculate the duration and get the result from the metric table instead



// variables available


// current: GlideRecord -   target incident


// definition: GlideRecord -   (this row)


var s = current.state;


if (s == 3 || s == 4 || s == 7)


  createMetric();




function createMetric() {


  var mi = new MetricInstance(definition, current);


  if (mi.metricExists())


      return;




  var gr = mi.getNewRecord();


  gr.start = current.sys_created_on;


  gr.end = current.sys_updated_on;


  gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());


  gr.calculation_complete = true;


  gr.insert();


}


find_real_file.png