Age field on task table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2017 10:34 PM
Hi All ,
I want to create a field which calculates age of the open tickets on the task table . I want it on Task table so that it can be used to calculate the age of all the tickets - incident , problem ,request etc.
How this can be done ? After creating this field it has to be used for reporting on task table , means all the open tickets -incident , problem ,request etc. ( ages ) can be represented in the report.
Thanks & Regards,
Snehal Khare

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2017 10:44 PM
Try this
Create a new field of type duration on task table. You may name it as 'Age'.
Write an After-Update Business Rule with condition 'When State Changes To Resolved'
Script:
calculateAge();
function calculateAge(){
var datedif = gs.dateDiff(current.sys_created_on,current.resolved_at);
current.u_age = datedif;
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2017 10:50 PM
Hi Aakash,
I don't want the age of the resolved tickets , I want to calculate the age of the ongoing tickets on which the assignee's are still working on .
How will this calculate the ages for incidents ,problem etc.. I guess the state values will be different for different table
Thanks
Snehal Khare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2017 10:57 PM
Hi Snehal,
1. Create one Filed in Task table.
2. Create Schedule job Daily it will run . This scheduled job will calculate the Active tickets age how many days back ticket is created.
Scheduled job:
var gr = new GlideRecord("task");
gr.addEncodedQuery('sys_class_name=incident^ORsys_class_name=problem^ORsys_class_name=sc_req_item');
gr.addActiveQuery();
gr.query();
while (gr.next())
{
var currentTime = gs.nowDateTime(); // Get the current date time in users timezone
var createdOn = gr.sys_created_on.getDisplayValue(); // Task created time in GMT(system default time zone)
var datedif = gs.dateDiff(createdOn, currentTime,true); // calculate in seconds
if(datedif<86400)
{
gr.u_age = 0;
}
else
{
gr.u_age = (datedif/86400);
}
gr.autoSysFields(false);
gr.update();
}
Please Hit Correct if this helpful

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2017 11:05 PM
Hi Snehal,
Perform the below mentioned steps.
1. Create a string type field on task table named 'Age'.
2. Create a schedule job as mentioned below. (Set the frequency of the job as per the frequency of the report run.)
var tsk= new GlideRecord('task');
tsk.addActiveQuery();
tsk.query();
while(tsk.next())
{
tsk.autoSysFields(false);
tsk.setWorkflow(false);
var inc_age =gs.dateDiff(tsk.sys_created_on.getDisplayValue(),gs.nowDateTime(),false);
var dur = new GlideDuration(inc_age);
dur=dur.getRoundedDayPart(); //This will give you age in days only
tsk.u_age=dur; //u_age is the backend name of the age field
tsk.update();
}
Hope this helps.
Regards
Ujjawal