diff --git a/Server-Side Components/Business Rules/Prevent Invalid Field Combinations/readme.md b/Server-Side Components/Business Rules/Prevent Invalid Field Combinations/readme.md new file mode 100644 index 0000000000..a4472f5867 --- /dev/null +++ b/Server-Side Components/Business Rules/Prevent Invalid Field Combinations/readme.md @@ -0,0 +1,16 @@ +In IT Service Management (ITSM), certain field combinations don’t make sense logically — for instance: +A High Priority incident should not have a Low Impact. +A Change Request marked as Emergency should not have Approval Type = Standard. +ServiceNow’s out-of-the-box (OOB) configurations can validate simple field requirements, but cannot enforce relational validation between two or more fields at the server-side level. +This custom Business Rule ensures data integrity by preventing users from saving or updating records when invalid field combinations occur. + +Details of Implementation +Created a new Business Rule: Prevent Invalid Field Combinations +Table: incident +Advanced: ✅ Checked +When to run: Before Insert & Before Update +Filter condition (optional): Leave blank or specify field conditions where you want this rule to apply +Script logic: +Checks if Impact = 3 (Low) and Priority = 1 (High). +Displays a user-friendly error message. +Aborts record submission to maintain data integrity. diff --git a/Server-Side Components/Business Rules/Prevent Invalid Field Combinations/script.js b/Server-Side Components/Business Rules/Prevent Invalid Field Combinations/script.js new file mode 100644 index 0000000000..9108ab1735 --- /dev/null +++ b/Server-Side Components/Business Rules/Prevent Invalid Field Combinations/script.js @@ -0,0 +1,9 @@ +(function executeRule(current, previous /*null when async*/) { + + // Example: Prevent record submission if Impact = Low and Priority = High + if (current.impact == 3 && current.priority == 1) { // 3 = Low, 1 = High + gs.addErrorMessage("Invalid combination: 'High' Priority cannot be set with 'Low' Impact."); + current.setAbortAction(true); // Prevents insert/update + } + +})(current, previous);