Skip to content

Commit 3d66b44

Browse files
Create README.md
1 parent f51aebf commit 3d66b44

File tree

1 file changed

+29
-0
lines changed
  • Server-Side Components/Script Includes/Recursive GlideRecord Fetcher

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Recursive GlideRecord Fetcher
2+
## Overview
3+
This snippet provides a reusable logic to recursively fetch child records from a parent record in ServiceNow. It is useful for traversing hierarchical relationships such as tasks, categories, CMDB CI relationships, or any table with a parent-child structure.
4+
5+
The logic prevents infinite loops by tracking visited records and supports nesting of children for structured output.
6+
7+
---
8+
9+
## Use Case
10+
- Fetch all subtasks under a parent task.
11+
- Traverse CMDB CI relationships recursively.
12+
- Build hierarchical views of organizational units or categories.
13+
14+
---
15+
16+
## Parameters
17+
| Parameter | Description |
18+
|------------------|-----------------------------------------------------------------------------|
19+
| `tableName` | Name of the table to query (e.g., `task`, `cmdb_ci`, `custom_table`) |
20+
| `parentField` | Field that links to the parent record (e.g., `parent`, `parent_id`) |
21+
| `parentSysId` | Sys ID of the root parent record to start traversal |
22+
23+
---
24+
25+
## Example Usage
26+
```javascript
27+
var fetcher = new RecursiveFetcher('task', 'parent');
28+
var hierarchy = fetcher.fetchChildren('abc123sysid'); // Replace with actual parent sys_id
29+
gs.info(JSON.stringify(hierarchy));

0 commit comments

Comments
 (0)