- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2018 02:22 AM
Need to create a Aging field in Incident Table to calculate the age of the tickets
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2018 02:27 AM
You need to create one field and write Scheduled job:
function updateAgingCategoryField() {
var elapsedTime = 0;
var aging = '';
var currentTimeNow = gs.nowDateTime();
var gr = new GlideRecord('incident');
gr.addEncodedQuery('u_aging_category!=>120^ORu_aging_category=');
gr.query();
while(gr.next()) {
elapsedTime = (gs.dateDiff(gr.opened_at, currentTimeNow, true)) /60/60/24;
//check to see when the item was created
if (elapsedTime <= 30) aging = '0-30';
if (elapsedTime > 30) aging = '31-60';
if (elapsedTime > 60) aging = '61-90';
if (elapsedTime > 90) aging = '91-120';
if (elapsedTime > 120) aging = '>120';
gr.setWorkflow(false); //skip any Business Rules
gr.autoSysFields(false); //do not update system fields
gr.u_aging_category = aging; //Custom Field
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2018 02:27 AM
You need to create one field and write Scheduled job:
function updateAgingCategoryField() {
var elapsedTime = 0;
var aging = '';
var currentTimeNow = gs.nowDateTime();
var gr = new GlideRecord('incident');
gr.addEncodedQuery('u_aging_category!=>120^ORu_aging_category=');
gr.query();
while(gr.next()) {
elapsedTime = (gs.dateDiff(gr.opened_at, currentTimeNow, true)) /60/60/24;
//check to see when the item was created
if (elapsedTime <= 30) aging = '0-30';
if (elapsedTime > 30) aging = '31-60';
if (elapsedTime > 60) aging = '61-90';
if (elapsedTime > 90) aging = '91-120';
if (elapsedTime > 120) aging = '>120';
gr.setWorkflow(false); //skip any Business Rules
gr.autoSysFields(false); //do not update system fields
gr.u_aging_category = aging; //Custom Field
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2018 02:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2018 02:50 AM
I update few things:
function updateAgingCategoryField() {
var gr = new GlideRecord('incident');
gr.addEncodedQuery(''); //Add the condition for which state you wanted to run and get the age, if not need kindly comment the line
//gr.setLimit(2);
gr.query();
while(gr.next()){
var datedif = gs.dateDiff(gr.sys_created_on,gs.nowDateTime());
var datetrim=datedif;
var index=datedif.indexOf(' ');
var aftertrim=datetrim.substring(0,index);
gr.u_aging_category = aftertrim;
gs.print(aftertrim);
gr.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2018 03:20 AM
Hi, Tried both , but the value are not updating in the Aging category Field