Skip to content

Commit 4972f94

Browse files
authored
Create README.md
1 parent c56ba8c commit 4972f94

File tree

1 file changed

+36
-0
lines changed
  • Core ServiceNow APIs/GlideDateTime/Next Business Window Calculator

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Next Business Window Calculator
2+
3+
## Problem
4+
You often need to compute the *next business window* for task scheduling, SLAs, or batch processing: “Start at 16:45, add 95 working minutes using schedule X and holiday set Y, and return both the end time and the ‘windows’ you traversed.” Native APIs give you the building blocks, but teams frequently re-invent this logic.
5+
6+
## Where to use it
7+
- Script Include utility callable from Business Rules, Flow/Schedule jobs, or Background Scripts
8+
- Works in *scoped* apps
9+
10+
## What it does
11+
- Accepts: start `GlideDateTime`, working minutes (integer), a schedule sys_id (or name), and an optional timezone
12+
- Uses `GlideSchedule` to hop across working/non-working periods and holidays
13+
- Returns:
14+
- `endGdt` — the calculated ending `GlideDateTime`
15+
- `segments` — an ordered list of working sub-segments used (start/end per segment), useful for audit/debugging
16+
- `consumedMinutes` — total minutes consumed
17+
18+
## Configuration
19+
At the top of the script you can configure:
20+
- Default schedule sys_id (fallback)
21+
- Default timezone (e.g., `Europe/London`)
22+
- Maximum safety iterations
23+
24+
## How it works
25+
The utility constructs a `GlideSchedule` from the provided schedule id, aligns the starting point, then iteratively consumes the requested working minutes across schedule segments (respecting holidays and timezone). It avoids recursion and uses a safety counter to prevent infinite loops.
26+
27+
## References
28+
- GlideSchedule (Scoped) API. ServiceNow Docs.
29+
https://www.servicenow.com/docs/ (GlideSchedule Scoped)
30+
- Server API overview (Zurich docs bundle). :contentReference[oaicite:1]{index=1}
31+
32+
## Example
33+
```js
34+
var util = new x_snc_example.NextBusinessWindow();
35+
var result = util.addWorkingMinutes('2025-10-21 16:45:00', 95, 'your_schedule_sys_id', 'Europe/London');
36+
// result.endGdt.getDisplayValue() -> "2025-10-22 09:20:00"

0 commit comments

Comments
 (0)