Skip to content

Commit f9ebac9

Browse files
Create script.js
1 parent 6e412f3 commit f9ebac9

File tree

1 file changed

+35
-0
lines changed
  • Server-Side Components/Business Rules/Sync Fields for two tables

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(function executeRule(current, previous /*null when async*/ ) {
2+
// Check if the Subject Person of case is empty
3+
if (gs.nil(current.subject_person))
4+
return;
5+
// Subject person field reference to User Table. Check if the HR profile is present for the user.
6+
var profileGR = new GlideRecord('sn_hr_core_profile');
7+
if (!profileGR.get(current.subject_person))
8+
return;
9+
10+
// Get all fields from the current record (case)
11+
var elements = current.getElements();
12+
13+
// Loop through each field on the case and get the name
14+
for (var i = 0; i < elements.size(); i++) {
15+
var field = elements.get(i);
16+
var fieldName = field.getName();
17+
18+
// Skip system fields and derived fields of hr profile (If any)
19+
if (fieldName.startsWith('sys_') || fieldName === 'hr_profile')
20+
continue;
21+
22+
var newValue = current.getValue(fieldName);
23+
var oldValue = previous.getValue(fieldName);
24+
25+
// Only act if value changed
26+
if (newValue != oldValue) {
27+
// Check if the same field exists in HR profile and is accessible
28+
if (profileGR.isValidField(fieldName)) {
29+
profileGR.setValue(fieldName, newValue);
30+
}
31+
}
32+
}
33+
profileGR.update();
34+
35+
})(current, previous);

0 commit comments

Comments
 (0)