Skip to content

Commit f3d0416

Browse files
authored
Create br_derive_dependent_fields.js
1 parent 932e34a commit f3d0416

File tree

1 file changed

+45
-0
lines changed
  • Core ServiceNow APIs/GlideElement/Smart Field Validation and Dependent Field Derivation Using getError() and setError()

1 file changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Name: Derive Dependent Fields
2+
// Table: Incident
3+
// When: before insert or before update
4+
// Order: 200
5+
6+
(function executeRule(current, previous /*null when async*/) {
7+
8+
// Only proceed if short_description changed or new record
9+
if (!(current.operation() === 'insert' || current.short_description.changes())) {
10+
return;
11+
}
12+
13+
var errorMsg = current.short_description.getError();
14+
15+
if (errorMsg) {
16+
gs.info('[BR:200 - Derive] Skipping field derivation due to prior error → ' + errorMsg);
17+
return;
18+
}
19+
20+
// Proceed only if no prior validation error
21+
var desc = current.getValue('short_description').toLowerCase();
22+
23+
// Example 1: Derive category
24+
if (desc.includes('server')) {
25+
current.category = 'infrastructure';
26+
current.subcategory = 'server issue';
27+
} else if (desc.includes('email')) {
28+
current.category = 'communication';
29+
current.subcategory = 'email problem';
30+
} else if (desc.includes('login')) {
31+
current.category = 'access';
32+
current.subcategory = 'authentication';
33+
} else {
34+
current.category = 'inquiry';
35+
current.subcategory = 'general';
36+
}
37+
38+
// Example 2: Derive impact
39+
if (desc.includes('critical') || desc.includes('outage')) {
40+
current.impact = 1; // High
41+
} else {
42+
current.impact = 3; // Low
43+
}
44+
45+
})(current, previous);

0 commit comments

Comments
 (0)