how to create calculated field that shows how long it took for a RITM to be closed

Atheher Fathima
Mega Guru

I have a requirement to create a calculated field that shows how long it took for a RITM to be closed

RITM Closed - RITM Open = Duration.

 

How can this be achieved. any help on this is greatly appreciated.

1 ACCEPTED SOLUTION

Mike_R
Kilo Patron
Kilo Patron

You can create a function field in your report

Mike_R_0-1681221078507.png

 

 

View solution in original post

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Atheher Fathima 

Is this required for reporting purpose or you want it as a field on RITM table?

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

@Ankur Bawiskar , this is basically for reporting purpose. I was advised by my team to create a SLA definition or a metric instead of creating a field on the sc_req_item table.

@Atheher Fathima 

that's correct. you can use metrics for this just like incident table

OR

you can use function field on the report created on RITM table.

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

Ravindra Duggi1
Tera Contributor

To create a calculated field that shows how long it took for a RITM (Requested Item) to be closed using a script and calculate it for existing RITM records, you can follow these steps:

 

  1. Create new Field
    1. Give the new field a name, such as "Time to Close", and select the data type as "Duration".
  2. In the "Calculated Script" field, enter the following script(Click on the advanced tab):

 

  1. (function() {
    var duration = 0;
    if (current.closed_at && current.opened_at) {
    var start = new GlideDateTime(current.opened_at.getDisplayValue());
    var end = new GlideDateTime(current.closed_at.getDisplayValue());
    var difference = gs.dateDiff(start, end, true);
    duration = difference / (60 * 60 * 1000);
    }
    return duration;
    })(); 
  2. This script calculates the time it took to close the RITM in hours by subtracting the "closed_at" date/time from the "Requested" date/time and dividing the result by the number of milliseconds in an hour.