From 5ae2a56307870658e21011601d95a366407e2045 Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Sun, 5 Oct 2025 16:13:15 +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\342\200\231s Data/Script.js" diff --git "a/Server-Side Components/Background Scripts/Update Field Based on Another Table\342\200\231s Data/Script.js" "b/Server-Side Components/Background Scripts/Update Field Based on Another Table\342\200\231s Data/Script.js" new file mode 100644 index 0000000000..f12a0a95f5 --- /dev/null +++ "b/Server-Side Components/Background Scripts/Update Field Based on Another Table\342\200\231s 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 557f3baaeaad232f5c45f69268376db42e908927 Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Sun, 5 Oct 2025 16:15:24 +0530 Subject: [PATCH 2/2] Create README.md --- .../README.md" | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 "Server-Side Components/Background Scripts/Update Field Based on Another Table\342\200\231s Data/README.md" diff --git "a/Server-Side Components/Background Scripts/Update Field Based on Another Table\342\200\231s Data/README.md" "b/Server-Side Components/Background Scripts/Update Field Based on Another Table\342\200\231s Data/README.md" new file mode 100644 index 0000000000..78abe0d758 --- /dev/null +++ "b/Server-Side Components/Background Scripts/Update Field Based on Another Table\342\200\231s Data/README.md" @@ -0,0 +1,9 @@ +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.