
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 06:19 PM - edited 03-05-2024 06:22 PM
Hello,
I have a requirement regarding getting the incident aged based on the created date, incident age will appear in the choice list if incident new will appear (Below 30 days) if the incident above 30 days (Above 30 days) and (Above 60 days) until (Above 90 days).
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 11:09 PM - edited 03-05-2024 11:11 PM
Hi @Community Alums I amended few changes,
Change your BR trigger to before insert/update and remove current.update from script.
Script:
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:32 PM
@Community Alums
You can write Business rule which should run on after insert/update, Below is the script you can use it:
(function executeRule(current, previous) {
// Calculate incident age based on created date
var createdDate = new GlideDateTime(current.getValue('sys_created_on'));
var today = new GlideDateTime();
var daysDifference = gs.dateDiff(createdDate, today, true); // Get difference in days
// Update incident age choice list field
if (daysDifference < 30) {
current.incident_age = 'Below 30 days';
} else if (daysDifference >= 30 && daysDifference < 60) {
current.incident_age = 'Above 30 days';
} else if (daysDifference >= 60 && daysDifference < 90) {
current.incident_age = 'Above 60 days';
} else {
current.incident_age = 'Above 90 days';
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 07:59 PM
@Community Alums
Seems like you daysDifference is falling between 30 to 60. Did you check on newly created incident you should get Below 30 days .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 08:02 PM
@Maddysunil
Should created in the choice the Below 30 days, Above 30 days and so on? if not it will show nothing on the Incident Age field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2024 08:08 PM
Hi @Community Alums
The gs.dateDiff will return in duration, you need to convert that to days as below
var duration = gs.dateDiff(createdAt, now, true); //calculate the difference
gs.info(duration );
var days = Math.floor(duration / 86400); //convert the duration to days
gs.info('Incident age in days: ' + days);
Harish