Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions -snippets/glide-helpers/safeGetBySysId.md
Original file line number Diff line number Diff line change
@@ -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);
25 changes: 25 additions & 0 deletions -snippets/glide-helpers/snippets/glide-helpers/debugLogger.md
Original file line number Diff line number Diff line change
@@ -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');
14 changes: 14 additions & 0 deletions `snippets/glide-helpers/commit-note-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# commit-note-template

> A small text template you can paste in PR comments or commit messages to help maintainers understand your change quickly.

**Use case:**
While submitting Hacktoberfest PRs, I realized reviewers appreciate clarity. This template summarizes your snippet purpose and what changed in 3 lines.

```text
### PR Summary
- Added new snippet: <name>.md
- Purpose: Explain what problem it solves and how it helps builders.
- Tested: Local review or example output shown in snippet.

Thank you for reviewing!
Loading