- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 04:54 AM
Hi,
If HR case is changes to awaiting acceptance state , Then Auto populate Due date on HR case with 5 Business days from when HR case is changes to awaiting acceptance state.
HR case is closed after 5 business days from when HR case is changes to awaiting acceptance state.
That's why we need to Due date when HR case is closed.
Thanks.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 07:51 AM
@Community Alums Please create a business rule on HR Case table as follows.
Here is the script.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
// Function to add business days
function addBusinessDays(startDate, days) {
var gdt = new GlideDateTime(startDate);
var counter = 0;
while (counter < days) {
gdt.addDaysLocalTime(1); // Increment the date by 1 day
// Check if the new day is a weekday (Monday to Friday)
var dayOfWeek = gdt.getDayOfWeekLocalTime();
if (dayOfWeek >= 2 && dayOfWeek <= 6) { // 2 = Monday, 6 = Friday
counter++; // Count only business days
}
}
return gdt;
}
// Only set the due date if it is empty
if (!current.due_date) {
// Get the current date and add 5 business days
var dueDate = addBusinessDays(new GlideDateTime(), 5);
current.due_date = dueDate;
}
})(current, previous);
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 06:25 AM
@Community Alums
this article talks about how to get and add business days. use similar logic and your schedule and add that in your BR script
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 07:51 AM
@Community Alums Please create a business rule on HR Case table as follows.
Here is the script.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
// Function to add business days
function addBusinessDays(startDate, days) {
var gdt = new GlideDateTime(startDate);
var counter = 0;
while (counter < days) {
gdt.addDaysLocalTime(1); // Increment the date by 1 day
// Check if the new day is a weekday (Monday to Friday)
var dayOfWeek = gdt.getDayOfWeekLocalTime();
if (dayOfWeek >= 2 && dayOfWeek <= 6) { // 2 = Monday, 6 = Friday
counter++; // Count only business days
}
}
return gdt;
}
// Only set the due date if it is empty
if (!current.due_date) {
// Get the current date and add 5 business days
var dueDate = addBusinessDays(new GlideDateTime(), 5);
current.due_date = dueDate;
}
})(current, previous);
Hope this helps.