From 6e412f36991bdfa5777b71cc0a02bc80161bc360 Mon Sep 17 00:00:00 2001 From: Chaitanya Lal <42643661+chaitanyalal18@users.noreply.github.com> Date: Thu, 23 Oct 2025 17:42:34 +0530 Subject: [PATCH 1/2] Create README.md --- .../Business Rules/Sync Fields for two tables/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Server-Side Components/Business Rules/Sync Fields for two tables/README.md diff --git a/Server-Side Components/Business Rules/Sync Fields for two tables/README.md b/Server-Side Components/Business Rules/Sync Fields for two tables/README.md new file mode 100644 index 0000000000..6cebac4140 --- /dev/null +++ b/Server-Side Components/Business Rules/Sync Fields for two tables/README.md @@ -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. From f9ebac9743865c2e494abbebfa43aa4e72d5f316 Mon Sep 17 00:00:00 2001 From: Chaitanya Lal <42643661+chaitanyalal18@users.noreply.github.com> Date: Thu, 23 Oct 2025 17:46:19 +0530 Subject: [PATCH 2/2] Create script.js --- .../Sync Fields for two tables/script.js | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Server-Side Components/Business Rules/Sync Fields for two tables/script.js diff --git a/Server-Side Components/Business Rules/Sync Fields for two tables/script.js b/Server-Side Components/Business Rules/Sync Fields for two tables/script.js new file mode 100644 index 0000000000..a4cc26599f --- /dev/null +++ b/Server-Side Components/Business Rules/Sync Fields for two tables/script.js @@ -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);