Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**Scenario**: Synchronize fields between two different tables.

**Example**: Any changes made to the fields on the New Hire HR Case for a user, where the same field also exists on the HR Profile, will automatically be updated on the HR Profile when the field is modified on the case.
Fields on the case that are derived from the HR Profile are excluded from this synchronization.

**Script Logic**: An after-update business rule that checks the updated fields in the current table (HR case) exist in the other table (HR Profile) and updates them accordingly.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(function executeRule(current, previous /*null when async*/ ) {
// Check if the Subject Person of case is empty
if (gs.nil(current.subject_person))
return;
// Subject person field reference to User Table. Check if the HR profile is present for the user.
var profileGR = new GlideRecord('sn_hr_core_profile');
if (!profileGR.get(current.subject_person))
return;

// Get all fields from the current record (case)
var elements = current.getElements();

// Loop through each field on the case and get the name
for (var i = 0; i < elements.size(); i++) {
var field = elements.get(i);
var fieldName = field.getName();

// Skip system fields and derived fields of hr profile (If any)
if (fieldName.startsWith('sys_') || fieldName === 'hr_profile')
continue;

var newValue = current.getValue(fieldName);
var oldValue = previous.getValue(fieldName);

// Only act if value changed
if (newValue != oldValue) {
// Check if the same field exists in HR profile and is accessible
if (profileGR.isValidField(fieldName)) {
profileGR.setValue(fieldName, newValue);
}
}
}
profileGR.update();

})(current, previous);
Loading