How to calculate Risk level on change table using Risk conditions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
when we click on related link (calculate risk) on change record it will set risk level. time window is a new custom choice field having options(business, on call), i tried this but only one condition satisfying but not other from the below. can any one help me here,
| Change Type | Service (business unit) | Time Window | auto set Risk Level |
| Normal | criticality 1 | On Call | High |
| Normal | criticality 2 | Business Hours | Moderate |
| Normal | Criticality 3 | On call | moderate |
| Normal | criticality 4 | Business Hours/On Call | Low |
| Normal | criticality 1 | business Hours | High |
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @kumar junior11 ,
When clicking “Calculate Risk”, only one condition works while others don’t. This happens due to case mismatches, overlapping conditions, or incorrect if/else logic.
Follow the below Steps
Step 1: Normalize Field Values
Make sure choice values match exactly (case + spacing).
var changeType = current.type + '';
var criticality = current.u_service_criticality + '';
var timeWindow = current.u_time_window + '';
criticality = criticality.toLowerCase().trim();
timeWindow = timeWindow.toLowerCase().trim();
Step 2: Use Proper if / else if Logic
Avoid multiple independent if statements.
if (changeType == 'Normal') {
if (criticality == 'criticality 1' && timeWindow == 'on call') {
current.risk = 'High';
} else if (criticality == 'criticality 1' && timeWindow == 'business hours') {
current.risk = 'High';
} else if (criticality == 'criticality 2' && timeWindow == 'business hours') {
current.risk = 'Moderate';
} else if (criticality == 'criticality 3' && timeWindow == 'on call') {
current.risk = 'Moderate';
} else if (
criticality == 'criticality 4' &&
(timeWindow == 'business hours' || timeWindow == 'on call')
) {
current.risk = 'Low';
}
}
Step 3: Debug Values (If Needed)
Check what values are actually coming from the form.
gs.info('Criticality: ' + criticality);
gs.info('Time Window: ' + timeWindow);
(View logs in System Logs → All)
Best Practices
Instead of hard-coding logic:
Create a Risk Matrix lookup table
Query the table based on Change Type, Criticality, and Time Window
Set Risk dynamically
✔ Easier maintenance
✔ No script changes needed later
✔ Cleaner logic
If this helps you then mark it as helpful and accept it as solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
I created a video on the same :
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]
****************************************************************************************************************
