From 675e853c6d0f96f3d385af3d4d0efe3d8c194bc1 Mon Sep 17 00:00:00 2001 From: aniketchavan-blip Date: Thu, 30 Oct 2025 22:30:36 +0530 Subject: [PATCH 1/2] Create safeGetBySysId utility for safe record retrieval This utility function simplifies fetching a GlideRecord by sys_id with built-in null checks and clear logging. It prevents repeated boilerplate code and ensures that missing records are clearly logged in sys.log. Includes an example usage for fetching an incident. --- -snippets/glide-helpers/safeGetBySysId.md | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 -snippets/glide-helpers/safeGetBySysId.md diff --git a/-snippets/glide-helpers/safeGetBySysId.md b/-snippets/glide-helpers/safeGetBySysId.md new file mode 100644 index 0000000000..f617813e50 --- /dev/null +++ b/-snippets/glide-helpers/safeGetBySysId.md @@ -0,0 +1,30 @@ +# safeGetBySysId + +> Safely fetch a GlideRecord by `sys_id` and log clearly if not found. + +**Use case:** +I often need to fetch a single record inside background scripts or Script Includes and don’t want to keep repeating the same `gr.get()` + null checks. This helper makes it a one-liner and keeps logs human-readable. + +```javascript +/** + * safeGetBySysId(table, sysId) + * Returns GlideRecord object or null if not found. + */ +function safeGetBySysId(table, sysId) { + if (!table || !sysId) { + gs.warn('safeGetBySysId: Missing parameters.'); + return null; + } + + var gr = new GlideRecord(table); + if (gr.get(sysId)) { + return gr; + } + + gs.warn('safeGetBySysId: No record found in ' + table + ' for sys_id ' + sysId); + return null; +} + +// Example: +var inc = safeGetBySysId('incident', '46d12b8a97a83110eaa3bcb51cbb356e'); +if (inc) gs.info('Found incident: ' + inc.number); From 49da63c9379d34fbd393b4d2a9da91d5c6037cfb Mon Sep 17 00:00:00 2001 From: aniketchavan-blip Date: Thu, 30 Oct 2025 22:34:44 +0530 Subject: [PATCH 2/2] Create debugLogger.md, feat(snippets/glide-helpers): add environment-aware logger, paginated query, and PR note template Environment-aware logging for server/client scripts, preventing production log clutter while easing debugging in sub-prod instances. --- .../snippets/glide-helpers/debugLogger.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 -snippets/glide-helpers/snippets/glide-helpers/debugLogger.md diff --git a/-snippets/glide-helpers/snippets/glide-helpers/debugLogger.md b/-snippets/glide-helpers/snippets/glide-helpers/debugLogger.md new file mode 100644 index 0000000000..5bee611cad --- /dev/null +++ b/-snippets/glide-helpers/snippets/glide-helpers/debugLogger.md @@ -0,0 +1,25 @@ +```markdown +# debugLogger + +> A simple environment-aware logging utility for client and server scripts. + +**Use case:** +In one of my projects, we wanted to log messages only in non-production environments without commenting them out each time. This small helper does that elegantly. + +```javascript +/** + * debugLogger(message, level) + * Logs only if NOT in production. + * Level can be 'info', 'warn', or 'error' + */ +var debugLogger = (function() { + var isProd = gs.getProperty('instance_name') === 'prod-instance'; // change per your instance + return function(msg, level) { + if (isProd) return; + level = level || 'info'; + gs[level]('[DEBUG] ' + msg); + }; +})(); + +// Example usage: +debugLogger('Checking record count...', 'info');