Skip to content

Commit 6ccab1b

Browse files
authored
Resource Capacity and Availability Viewer (Daily Basis) (#2343)
* Create ResourceCapacityAndAvailabilityViewerDailyBasis.js * Create ResourceCapacityAndAvailabilityViewerDailyBasis.js * Create README.md * Delete Specialized Areas/Resource Management/ResourceCapacityAndAvailabilityViewerDailyBasis.js
1 parent 2765bed commit 6ccab1b

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
This script will output a User's Capacity and Availability hourly breakdown of a on a daily basis for a given range.
2+
This is normally not easily accessible in the platform as there are only Weekly and Monthly aggregates in the platform (resource_aggregate_weekly and resource_aggregate_monthly).
3+
4+
If there is a Schedule change, the Capacity and Availablility aggregates may be out of sync as well.
5+
So, this script will show you what the breakdown is based on the current Schedule.
6+
7+
Of course, you need "Resource Management" installed to use this which typically comes as part of the "PPM Standard" plugin.
8+
9+
To use it, call the "getUserCapacity" function. You can run this in the [System Defintion > Scripts - Background] module
10+
11+
- Argument 1 can be a Sys ID or a User ID from the sys_user table
12+
- Argument 2 is the Start Date of the range you care about in YYYY-MM-DD format
13+
- Argument 3 is the End Date of the range you care about in YYYY-MM-DD format
14+
15+
Example calls:
16+
17+
getUserCapacity("ae44946c835cba90cac7a5e0deaad38f", "2025-01-01", "2025-02-28");
18+
19+
OR
20+
21+
getUserCapacity("abel.tuter", "2026-10-01", "2026-10-31");
22+
23+
Example output (left number is Capacity, right number is Availability):
24+
25+
2025-01-01: 6 | 6
26+
2025-01-02: 6 | 6
27+
2025-01-03: 6 | 6
28+
2025-01-04: 0 | 0
29+
2025-01-05: 0 | 0
30+
2025-01-06: 6 | 5
31+
2025-01-07: 6 | 6
32+
2025-01-08: 6 | 6
33+
2025-01-09: 6 | 6
34+
2025-01-10: 6 | 6
35+
2025-01-11: 0 | 0
36+
2025-01-12: 0 | 0
37+
2025-01-13: 6 | 5
38+
2025-01-14: 6 | 6
39+
2025-01-15: 6 | 6
40+
2025-01-16: 6 | 6
41+
2025-01-17: 6 | 6
42+
2025-01-18: 0 | 0
43+
2025-01-19: 0 | 0
44+
2025-01-20: 6 | 5
45+
2025-01-21: 6 | 6
46+
2025-01-22: 6 | 6
47+
2025-01-23: 6 | 6
48+
2025-01-24: 6 | 6
49+
2025-01-25: 0 | 0
50+
2025-01-26: 0 | 0
51+
2025-01-27: 6 | 5
52+
2025-01-28: 6 | 6
53+
2025-01-29: 6 | 6
54+
2025-01-30: 6 | 6
55+
2025-01-31: 6 | 6
56+
57+
Breakdown for Month --- Capacity: 138 --- Availability: 134
58+
59+
2025-02-01: 0 | 0
60+
2025-02-02: 0 | 0
61+
2025-02-03: 6 | 6
62+
2025-02-04: 6 | 6
63+
2025-02-05: 6 | 6
64+
2025-02-06: 6 | 6
65+
2025-02-07: 6 | 6
66+
2025-02-08: 0 | 0
67+
2025-02-09: 0 | 0
68+
2025-02-10: 6 | 6
69+
2025-02-11: 6 | 6
70+
2025-02-12: 6 | 6
71+
2025-02-13: 6 | 6
72+
2025-02-14: 6 | 6
73+
2025-02-15: 0 | 0
74+
2025-02-16: 0 | 0
75+
2025-02-17: 6 | 6
76+
2025-02-18: 6 | 6
77+
2025-02-19: 6 | 6
78+
2025-02-20: 6 | 6
79+
2025-02-21: 6 | 6
80+
2025-02-22: 0 | 0
81+
2025-02-23: 0 | 0
82+
2025-02-24: 6 | 6
83+
2025-02-25: 6 | 6
84+
2025-02-26: 6 | 6
85+
2025-02-27: 6 | 6
86+
2025-02-28: 6 | 6
87+
88+
Breakdown for Month --- Capacity: 120 --- Availability: 120
89+
90+
Total days in range: 59
91+
Total working days in range: 43
92+
Total capacity: 258
93+
Total availability: 254
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Set first argument to either a User ID or a Sys ID from the "sys_user" table
2+
// Set second and thirt arguments to Start Date and End Date respectively in format YYYY-MM-DD
3+
getUserCapacity("ae44946c835cba90cac7a5e0deaad38f", "2025-01-01", "2025-02-28");
4+
5+
function getUserCapacity(userIdOrSysId, startDateString, endDateString) {
6+
var grUser = new GlideRecord("sys_user");
7+
if(grUser.get(userIdOrSysId)) {
8+
var startDate = new GlideDate(startDateString);
9+
var endDate = new GlideDate(endDateString);
10+
11+
var capacityApi = new RMCapacityAPI(startDateString, endDateString);
12+
var capacityObj = capacityApi.getCapacityForUser(grUser.getUniqueValue());
13+
var availabilityObj = capacityApi.getAvailabilityForUser(grUser.getUniqueValue());
14+
var totalDaysInRange = GlideDateTime.subtract(startDate, endDate).getDayPart() + 1;
15+
var totalWorkingDaysInRange = 0;
16+
17+
var dateIterator = GlideDateTime(startDateString);
18+
19+
var currentMonth = dateIterator.getMonthUTC();
20+
var monthlyTotalCapacity = 0;
21+
var monthlyTotalAvailability = 0;
22+
var totalCapacity = 0;
23+
var totalAvailability = 0;
24+
25+
for (var i = 0; i < capacityObj.length; i++) {
26+
27+
var month = dateIterator.getMonthUTC();
28+
if (month != currentMonth) {
29+
gs.info("");
30+
gs.info("Breakdown for Month --- Capacity: " + monthlyTotalCapacity + " --- Availability: " + monthlyTotalAvailability);
31+
gs.info("");
32+
currentMonth = month;
33+
monthlyTotalCapacity = 0;
34+
monthlyTotalAvailability = 0;
35+
}
36+
37+
gs.info(dateIterator.getDate() + ": " + capacityObj[i] + " | " + availabilityObj[i]);
38+
dateIterator.add(86400000);
39+
if (capacityObj[i] > 0) {
40+
totalWorkingDaysInRange++;
41+
totalCapacity += capacityObj[i];
42+
totalAvailability += availabilityObj[i];
43+
monthlyTotalCapacity += capacityObj[i];
44+
monthlyTotalAvailability += availabilityObj[i];
45+
}
46+
}
47+
48+
gs.info("");
49+
gs.info("Breakdown for Month --- Capacity: " + monthlyTotalCapacity + " --- Availability: " + monthlyTotalAvailability);
50+
gs.info("");
51+
52+
gs.info("Total days in range: " + totalDaysInRange);
53+
gs.info("Total working days in range: " + totalWorkingDaysInRange);
54+
gs.info("Total capacity: " + totalCapacity);
55+
gs.info("Total availability: " + totalAvailability);
56+
}
57+
}

0 commit comments

Comments
 (0)