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. 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(); + } +}