Catalog Task (up-to-the-minute) Aging Report

abelangulo
Kilo Contributor

Hello,

I have a requirement from management asking for a list report showing up-to-that-minute aging of all open/active Catalog Tasks. In other words, they want to be able to see how long (duration) since the task was created, regardless of the current task state.

I already provided them a chart showing the date ranges, but that's not what they want to see.

Has anybody done this...? Any ideas on how to accomplish it...?

Thank you in advance.

1 ACCEPTED SOLUTION

Hi Abel,



Not a problem.   I would actually create a new field rather than using the Duration field itself.   Here's the approach:



1.   Personalize the form


2.   From the Create New Field in the bottom right, select Duration from the type and give the field a name


3.   Click Add to add the field to the form, position it and click Save


4.   From the form, right click the field and click Personalize Dictionary.


5.   Click the Read Only checkmark, click the Calculated checkmark


6.   In the calculated field, enter the following:


gs.dateDiff(current.opened_at.getDisplayValue(), new GlideDateTime().getDisplayValue());



That ought to work.



Setting the Duration Field Value - ServiceNow Wiki


GlideDateTime - ServiceNow Wiki


View solution in original post

14 REPLIES 14

figured it out with a bit of playing about



gs.dateDiff(current.opened_at.getDisplayValue(), current.closed_at.getDisplayValue());



Thanks again for your help.


sorry bout that missed the reply yesterday asking for help.. yep that is it... if you need any field name from a form there are a number of ways to get it... the easiest IMHO to get the correct name for ANY field and see the format of the value.. is to open a form view... right click the header and select show xml you will see the xml payload for the record including every field on the table and how it is formatted in the payload.. quite helpful when coding


Thanks Doug, that is useful


gyedwab
Mega Guru

If you want to do this without code, against any date-time field, and allow users to specify their own age ranges, you can use Explore Analytics.



I uploaded a video showing an example here (it uses Incident, but it works the same anywhere):



Creating Incident Aging Reports for ServiceNow - YouTube


davida1
Giga Expert

In the Orlando & Paris releases, there are two fields on Service Catalog tasks; Duration (calendar_duration) and Business Duration (business_duration).

We set these via a Fix script, run on tasks with State = "Closed Complete", which contains (in part):

while (dmagr.next()) {

var bus_duration = '';
var cal_duration = '';

// Update the fields that indicate the time/duration of the task
// Keep track of duration as a glide_duration value (dd hh:mm:ss) and as a pure number of seconds.

var opened = dmagr.opened_at.getDisplayValue();
var closed = dmagr.closed_at.getDisplayValue();
gs.print('Task created: ' + opened + '; Task completed: ' + closed);

// Calculate 'Business duration' against global system schedule
var sched = new GlideSchedule(gs.getProperty('glide.ui.autoclose.schedule'));

bus_duration = sched.duration(dmagr.opened_at.getGlideObject(), dmagr.closed_at.getGlideObject());

gr.business_duration = bus_duration;

// Calculate 'Calendar duration'
cal_duration = gs.dateDiff(dmagr.opened_at, dmagr.closed_at);
dmagr.calendar_duration = cal_duration;

gr.update(); // Commit the change

}

Oddly enough, the Fix script works like a champ, but the same logic in a Business rule sets the field to be "1218 Days 9 Minutes", so if you can help me fix it, I would appreciate it!

David A