- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 01-02-2018 05:36 AM
HIi All,
This post covers the simpler way to show incident open date to current date/time (Incident age)Live Tracking.
Step:1
I'm creating one Duration field in incident Form.
Step:2
After create style's.
Step:3
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, After create one Incident List Report and add to this field in report.Save and Run your report its looking like below .
Important: 1.If Incident is closed its automatically color(RED) change and stop calculate duration(Incident age).
2.If you want update existing records go through Scheduled job.
Thanks,
Srinath Patel
This document was generated from the following discussion: Incident Age Calculate Report-Live Tracking
- 5,434 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks srinath its very help to me.
Thanks,
Prasad
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Nice artical

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
Awesome solution proposal. Thank you for providing this.
A few questions that I have in implementing this.
1. What are the performance impacts?
2. With this being a query business rule as well, is there an impact when I query 100+ active records that now have to have the duration field updated?
3. What if there are multiple people querying the same incident list, do we all update the record? Are there conflicts?
4. Lastly, if I executed the query, does the record show I updated the record since the duration field is being updated?
I will be testing this myself, but thought maybe you had some feedback with your solution already in place.
Thanks again for your contribution!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
If you are running Kingston, take a look at replacing the Business Rule with a GlideFunction field.
This moves the calculation from the application side to the database. I haven't tested this, but it should give a performance boost. In addition, GlideFunctions can be used in a query. If someone queried the u_incident_age field in this example, they would get incorrect results (since what is stored in the database is what was calculated on the last read instead of what is there right now).
If you are pre-Kingston, you may want to look at doing this as a Calculated Field instead of the BR. Functionally, I believe it should be the same, but the logic will be more self-contained.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Srinath Patel,
Thank you for posting this solution. I am using it to calculate the age of a ticket on a custom table I have created. The Age field is working as expected with one exception. On the initial submission of the form, the age updates every 10 seconds without the need to refresh the page as stated above. The "clock" then stops and will only reflect an accurate age reading once an update is made to the form. The calculation stops updating at inconsistent time intervals across my trial examples. Some stop at 10 minutes, others at 20 seconds and so on. No changes are made to the form from submission to the timer "stopping".
I have been troubleshooting in the following ways:
The table extends task and there are several other business rules running as well. I adjusted the order of the Calculate age business rule, though that did not resolve the issue. I do have the field set to read-only and there are some ACL restricting read and write functionality and am not entirely sure these ACLs may not be to blame.
After researching I came across some articles stating that developers should refrain from using current.update().
https://community.servicenow.com/community?id=community_question&sys_id=a3fb0725db9cdbc01dcaf3231f96199a
I altered the script in an effort to remove the current.update(), though couldn't get it quite working.
Following the article's suggestion and checking the error log produced the following:
In the above instruction for the business rule, it states: When to run = async
Though the function warns that the script will be null when async. I am not sure if this is what is causing the issue or if it is related to recursion addressed in the article I listed above.
I have tried adjusting the "when to run" condition with no success and am unable to find a suitable alternative to current.update in order to avoid recursion if that's the problem. I am out of ideas on how to fix the error and still achieve the desired field calculation and would appreciate the insight of another set of eyes. I would greatly appreciate anyone's insight and/or guidance into what the issue is and what steps need to be taken in order to resolve it. I thank you in advance for your help!
Kind regards,
Volenté