- 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 03:43 AM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2018 03:27 AM
Hi Bijender,
I'm creating one Duration field in incident Form.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2018 03:59 AM
I'm creating one Duration field in incident Form.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2021 11:26 PM
will it stopped after incident is closed?