
- 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:17 PM - edited ‎03-05-2024 07:34 PM
Hi @Community Alums here is the script which can do, create after insert/update BR
script:
var days;
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)
{
//set choice list
}
if(days < 30 and days <= 60)
{
//set choice list
}
if(days > 60)
{
//set choice list
}
Harish

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 08:07 PM
Hi @Community Alums Have you tried the script I shared? 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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 08:10 PM
Hello @Harish KM
I've tried your script showing nothing

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 08:14 PM
Hi @Community Alums Kindly share your updated script, I can help to fix
Harish