Need to create a Aging field in Incident Table to calculate the age of the tickets

bijender1
Tera Contributor

Need to create a Aging field in Incident Table to calculate the age of the tickets

1 ACCEPTED SOLUTION

Shashikant Yada
Tera Guru

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();
}
}

View solution in original post

8 REPLIES 8

Can you add the logs and check

var aftertrim=datetrim.substring(0,index);
gr.u_aging_category = aftertrim;

gs.log('age date',aftertrim);

gs.log('age date Incident',gr.u_aging_category);

Kush Bajpai2
Tera Contributor

Hi Bijender,

 

 

I'm creating   one Duration field   in incident Form.

find_real_file.png

 

Then create Business Rule.

Name:Incident Age Calculate

Table:Incident

When to Run :Async(Insert,Update,Query)

Filter Condition:Active is True

Script:

(function executeRule(current, previous /*null when async*/) {

calculateAge();

function calculateAge()

{

var datedif = gs.dateDiff(current.sys_created_on.getDisplayValue(), gs.nowDateTime(),false);

current.u_incident_age = datedif;

current.update();

}

})(current, previous);

 

Please mark it helpful if it resolves your issue

Community Alums
Not applicable

I'm creating   one Duration field   in incident Form.

find_real_file.png

Then create Business Rule.

Name:Incident Age Calculate

Table:Incident

When to Run :Async(Insert,Update,Query)

Filter Condition:Active is True

Script:

(function executeRule(current, previous /*null when async*/) {

calculateAge();

function calculateAge()

{

var datedif = gs.dateDiff(current.sys_created_on.getDisplayValue(), gs.nowDateTime(),false);

current.u_incident_age = datedif;

current.update();

}

})(current, previous);

 

Note: create one incident then observe Incident age field its automatically update every 10 sec with out refresh page

 

Please mark Helpful if it resolves your issue

@Kush Bajpai 

will it stopped after incident is closed?