- 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 08:18 PM
(function executeRule(current, previous /*null when async*/) {
var createdAt= new GlideDateTime(current.sys_created_on); //get the incident opened_at date
var now = new GlideDateTime(); //get the current date and time
var duration = gs.dateDiff(createdAt, now, true); //calculate the difference
days = Math.floor(duration / 86400); //convert the duration to days
gs.info('Incident age in days: ' + days);
if(days < 30)
{
current.u_incident_time = 'Below 30 days';
}
if(days < 30 && days <= 60)
{
current.u_incident_time = 'Above 30 days';
}
if(days > 60)
{
current.u_incident_time = 'Above 60 days';
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 08:33 PM
Hi @Community Alums tested in PDI, works as expected, please find below script,
Your BR should be after insert/update
script:
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 09:55 PM
Hello @Harish KM
Not working on me, should i add those choices in the choice list or not?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 09:56 PM
Hi @Community Alums you need to have choices in the field to display , what type of field are you using for Incident time?
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 10:00 PM
@Harish KM
Choice field