Created a flow designer to Auto close incident that are not update more than 3 Business Days.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 04:46 AM
Hello Everyone,
I have created a flow designer to Auto close incidents that are not update more than 3 Business Days for particular group and the flow is working correctly. However the flow should not consider Saturday and Sunday as business days.
For example, the incident was last updated on 1st Nov 2024 and its Friday. If we count 3 days continuously the incident should close on Monday because it will reach 3 days.
But, As per our requirement the incident should close on Wednesday cause it should exclude saturday and sunday as these days are not business days.
How and where I should add these condition in flow designer to consider only 3 business days.
I appreciate any help.
Thankyou,
Bala
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 05:51 AM - edited 11-04-2024 05:59 AM
HI @Balasai peela ,
Why you need flow designer, we have OOB configuration that you can set to auto close the incident.
Navigate to "Incident Properties"
Also you can use below script to close the ticket in 5 business days.
updateRecords();
function updateRecords(){
try{
var inc = new GlideRecord('incident');
inc.addQuery('state', 6);
inc.query();
while(inc.next()){
var start = new GlideDateTime(inc.sys_created_on);
var nowTime = new GlideDateTime();
var days = getDateDiffExcWeekends(start,nowTime);
// if days more than 5
if(days >=5){
inc.state = 7;
inc.incident_state = 7;
inc.active = false;
inc.update();
}
}
}
catch(ex){
gs.info(ex);
}
}
function getDateDiffExcWeekends(start , end){
var days = 0;
while (start < end) {
start.addDaysUTC(1);
if (start.getDayOfWeekUTC() != 6 && start.getDayOfWeekUTC() != 7){
days++ ;
}
}
return days;
}
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 05:52 AM
Because that runs on calendar days, not business
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 06:29 AM
Hi @Runjay Patel ,
Thankyou for your reply,
Apologies, Here we are doing this requirement only for 1 particular assignment group. I forgot to mention on the Flow designer condition.
Scenario: Incident Updated on a Friday
1. Incident Last Updated on Friday:
Let’s assume an incident is updated on Friday, November 1st.
2. 3 Business Days Requirement:
We want the incident to auto-close after 3 business days of inactivity.
3. Flow Runs Daily but Only Counts Business Days:
The flow will run every day (including Saturday and Sunday), but the 3-day inactivity period only counts Monday to Friday as business days.
How It Works Day by Day:
Expected Outcome:
The flow will check the incident daily, but the script will only count Monday, Tuesday, and Wednesday as business days.
By Wednesday, November 6th, the incident will reach 3 business days of inactivity and will meet the auto-close condition.
The incident should then be auto-closed on Wednesday.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 07:00 AM
Hi @Balasai peela ,
The script which i have given to you it will work and count business days only. you need to change only from 7 to 3 in properties, rest script will take care.
For specific assignment group just add the condition using add query?
You just need to update the code in BR.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------