|
| 1 | +# Weekly Incident Trend Analysis |
| 2 | + |
| 3 | +## Overview |
| 4 | +Compares incident volume week-over-week to track trends and identify anomalies in incident patterns. |
| 5 | + |
| 6 | +## What It Does |
| 7 | +- Counts incidents created last week |
| 8 | +- Counts incidents created this week |
| 9 | +- Calculates the difference (increase/decrease) |
| 10 | +- Logs the trend analysis result |
| 11 | + |
| 12 | +## Use Cases |
| 13 | +- Monitor incident volume trends |
| 14 | +- Identify weeks with unusual spike/drop in incidents |
| 15 | +- Track service health over time |
| 16 | +- Alert on incident volume anomalies |
| 17 | +- Weekly reporting on incident patterns |
| 18 | + |
| 19 | +## Files |
| 20 | +- `incident_trend_analyzer.js` - GlideAggregate-based trend analysis |
| 21 | + |
| 22 | +## How to Use |
| 23 | + |
| 24 | +### Option 1: Run as Scheduled Job |
| 25 | +1. Go to **System Scheduler > Scheduled Jobs** |
| 26 | +2. Create new Scheduled Job |
| 27 | +3. Copy code from `incident_trend_analyzer.js` |
| 28 | +4. Set to run weekly (e.g., every Monday morning) |
| 29 | +5. Check logs for trend results |
| 30 | + |
| 31 | +### Option 2: Run from Background Script |
| 32 | +1. Go to **System Diagnostics > Script Background** |
| 33 | +2. Copy and execute the code |
| 34 | +3. View results in logs |
| 35 | + |
| 36 | +### Example Usage |
| 37 | +```javascript |
| 38 | +// The script automatically: |
| 39 | +// 1. Queries incidents from last week |
| 40 | +// 2. Queries incidents from this week |
| 41 | +// 3. Compares counts |
| 42 | +// 4. Logs: "Incident count increased by X compared to last week." |
| 43 | +``` |
| 44 | + |
| 45 | +## Output Examples |
| 46 | +``` |
| 47 | +"Incident count increased by 15 compared to last week." |
| 48 | +"Incident count decreased by 8 compared to last week." |
| 49 | +"No change in incident volume week-over-week." |
| 50 | +``` |
| 51 | + |
| 52 | +## Key Features |
| 53 | +- Uses `GlideAggregate` for efficient counting |
| 54 | +- No heavy querying of individual records |
| 55 | +- Date range filtering using ServiceNow helper functions |
| 56 | +- Week-over-week comparison logic |
| 57 | + |
| 58 | +## Requirements |
| 59 | +- ServiceNow instance with Incident table |
| 60 | +- Access to run Background Scripts or create Scheduled Jobs |
| 61 | +- Read access to incident records |
| 62 | + |
| 63 | +## Performance Notes |
| 64 | +- Very efficient - uses aggregation not GlideRecord loops |
| 65 | +- Minimal database impact |
| 66 | +- Suitable for running on schedule without performance concerns |
| 67 | + |
| 68 | +## Customization |
| 69 | +To track other tables (Change, Problem, etc.): |
| 70 | +```javascript |
| 71 | +// Change 'incident' to your table name |
| 72 | +var lastWeekAgg = new GlideAggregate('change_request'); |
| 73 | +var thisWeekAgg = new GlideAggregate('change_request'); |
| 74 | +``` |
| 75 | + |
| 76 | +To track different time periods: |
| 77 | +```javascript |
| 78 | +// Use other helper functions: |
| 79 | +// gs.beginningOfThisMonth(), gs.endOfThisMonth() |
| 80 | +// gs.beginningOfThisYear(), gs.endOfThisYear() |
| 81 | +// gs.addMonthsUTC(), gs.addDaysUTC() for custom ranges |
| 82 | +``` |
| 83 | + |
| 84 | +## Related ServiceNow APIs |
| 85 | +- [GlideAggregate](https://docs.servicenow.com/bundle/sandiego-application-development/page/app-store/dev_apps/concept/c_UsingGlideAggregate.html) - Used for efficient counting |
| 86 | +- [GlideSystem Date Functions](https://docs.servicenow.com/bundle/sandiego-application-development/page/app-store/dev_apps/concept/c_SystemDateFunctions.html) |
0 commit comments