From 8fee2ed188549cb5695e57dd72297cd148e3d85a Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Sun, 5 Oct 2025 16:27:23 +0530 Subject: [PATCH 1/2] Create Script.js --- .../Script.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Update Field Based on Another Table Data/Script.js diff --git a/Server-Side Components/Background Scripts/Update Field Based on Another Table Data/Script.js b/Server-Side Components/Background Scripts/Update Field Based on Another Table Data/Script.js new file mode 100644 index 0000000000..f12a0a95f5 --- /dev/null +++ b/Server-Side Components/Background Scripts/Update Field Based on Another Table Data/Script.js @@ -0,0 +1,11 @@ +var userGr = new GlideRecord('sys_user'); +userGr.query(); +while (userGr.next()) { + var incGr = new GlideRecord('incident'); + incGr.addQuery('caller_id', userGr.sys_id); + incGr.query(); + while (incGr.next()) { + incGr.u_department = userGr.department; // Assuming custom field u_department + incGr.update(); + } +} From 034d52dd86f82eddc36ec4e99057a187144de338 Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Sun, 5 Oct 2025 16:28:54 +0530 Subject: [PATCH 2/2] Create README.md --- .../Update Field Based on Another Table Data/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Update Field Based on Another Table Data/README.md diff --git a/Server-Side Components/Background Scripts/Update Field Based on Another Table Data/README.md b/Server-Side Components/Background Scripts/Update Field Based on Another Table Data/README.md new file mode 100644 index 0000000000..ad352d866d --- /dev/null +++ b/Server-Side Components/Background Scripts/Update Field Based on Another Table Data/README.md @@ -0,0 +1,9 @@ +This script Update incidents with the department of their caller +Loops through every user in the sys_user table. +For each user, finds all incidents where they are the caller (caller_id matches sys_id of the user). +For each matching incident: Copies the user's department value, Sets it on the incident's custom field u_department. + +Use Case Example: + +Let’s say you want each incident record to store the caller’s department, but this info is only on the user profile. +This script pulls it from the user and updates all related incident records.