From 4417463af3ae6b2633e4dfe9f2abb9d6073edf92 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 9 Oct 2025 16:42:09 +0200 Subject: [PATCH 1/4] Update README.md Updated the readme to combine the readme for both JS files. There are now 2 readme's which is confusing and reported in issue #1903 --- .../Get Reference Record/README.md | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Core ServiceNow APIs/GlideRecord/Get Reference Record/README.md b/Core ServiceNow APIs/GlideRecord/Get Reference Record/README.md index 5735162344..c6a9bbf547 100644 --- a/Core ServiceNow APIs/GlideRecord/Get Reference Record/README.md +++ b/Core ServiceNow APIs/GlideRecord/Get Reference Record/README.md @@ -1,3 +1,19 @@ -# Get Reference Record +# Get Reference Record with GlideRecord -If you need a GlideRecord object for a reference item, then getRefRecord() is the method to use. You must call isValidRecord() after getting the reference record as getRefRecord() does not throw errors for empty values. isValidRecord() will be true if your reference record was found. +This folder contains examples demonstrating how to retrieve and work with reference records using `getRefRecord()` in ServiceNow server-side scripting. + +## Overview + +`getRefRecord()` is used to retrieve the full GlideRecord object of a reference field. This allows access to additional fields from the referenced record, such as `name`, `email`, or other attributes beyond the display value. + +Because `getRefRecord()` does not throw an error when the reference field is empty or invalid, it is important to use `isValidRecord()` to verify that the reference was successfully retrieved before accessing its fields. + +## Script Descriptions + +- get_assignment_group_from_incident.js retrieves the assignment group from an incident record and prints its name if the group exists. +- get_requested_by_user.js retrieves a change request by `sys_id`, then accesses the `requested_by` user record. If valid, it prints the user's username and email. + +## Best Practices + +- Always use `isValidRecord()` after calling `getRefRecord()` to ensure the reference is valid. +- Use `getRefRecord()` when you need to access fields from a referenced record, not just its display value. From 2a1f1b9edde196a65a32697cad43c38e41fd3804 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 9 Oct 2025 16:43:14 +0200 Subject: [PATCH 2/4] Delete Core ServiceNow APIs/GlideRecord/Get Reference Record/Readme_Soumyadeep.md Removed additional readme, as the naming is not in line, and another readme already exists. Updated the other readme to include the content of this one + improvements. --- .../GlideRecord/Get Reference Record/Readme_Soumyadeep.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 Core ServiceNow APIs/GlideRecord/Get Reference Record/Readme_Soumyadeep.md diff --git a/Core ServiceNow APIs/GlideRecord/Get Reference Record/Readme_Soumyadeep.md b/Core ServiceNow APIs/GlideRecord/Get Reference Record/Readme_Soumyadeep.md deleted file mode 100644 index 698348475d..0000000000 --- a/Core ServiceNow APIs/GlideRecord/Get Reference Record/Readme_Soumyadeep.md +++ /dev/null @@ -1,3 +0,0 @@ -This script will glide for a particular record whose sys id has been provided -It will fetch the record and then use getRefRecord() to fetch the requested by user details. -If the user is a valid record, then it will fetch the user_name and email. From 2f8004a91943a7d6ee7c8d7c8d628ec689cd6dc4 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 9 Oct 2025 16:44:53 +0200 Subject: [PATCH 3/4] Rename script.js to get_assignment_group_from_incident.js Rename the script to account for the second JS file in this folder. This is the name also referred to in the readme --- .../{script.js => get_assignment_group_from_incident.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Core ServiceNow APIs/GlideRecord/Get Reference Record/{script.js => get_assignment_group_from_incident.js} (100%) diff --git a/Core ServiceNow APIs/GlideRecord/Get Reference Record/script.js b/Core ServiceNow APIs/GlideRecord/Get Reference Record/get_assignment_group_from_incident.js similarity index 100% rename from Core ServiceNow APIs/GlideRecord/Get Reference Record/script.js rename to Core ServiceNow APIs/GlideRecord/Get Reference Record/get_assignment_group_from_incident.js From 78265fc724233c439a81ce15cf94eb99a4d76010 Mon Sep 17 00:00:00 2001 From: Willem Date: Thu, 9 Oct 2025 16:45:56 +0200 Subject: [PATCH 4/4] Rename GetRecordRequestedBy_Soumyadeep.js to get_requested_by_user.js Renamed the file to account for a second js in this folder. This file name is also referenced in the updated readme. --- ...etRecordRequestedBy_Soumyadeep.js => get_requested_by_user.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Core ServiceNow APIs/GlideRecord/Get Reference Record/{GetRecordRequestedBy_Soumyadeep.js => get_requested_by_user.js} (100%) diff --git a/Core ServiceNow APIs/GlideRecord/Get Reference Record/GetRecordRequestedBy_Soumyadeep.js b/Core ServiceNow APIs/GlideRecord/Get Reference Record/get_requested_by_user.js similarity index 100% rename from Core ServiceNow APIs/GlideRecord/Get Reference Record/GetRecordRequestedBy_Soumyadeep.js rename to Core ServiceNow APIs/GlideRecord/Get Reference Record/get_requested_by_user.js