Skip to content

Commit 56294db

Browse files
Create readfile.md
1 parent 11d9b79 commit 56294db

File tree

1 file changed

+50
-0
lines changed
  • Server-Side Components/Background Scripts/Extract Value from JSON

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Extract User Roles from JSON
2+
3+
---
4+
5+
## Overview
6+
This ServiceNow background script takes a JSON of usernames and their titles (roles) and groups all roles under each **unique user**.
7+
It prints the result in the **System Logs** in ServiceNow. This helps admins quickly see **unique users and all their roles**, avoiding duplicates.
8+
9+
---
10+
11+
## Use Case
12+
For example, if a user appears multiple times with different roles:
13+
14+
- `tammie.schwartzwalde` appears as both:
15+
- Senior Auditor
16+
- Payroll Generalist
17+
18+
The script will show **all roles together** for that user, without repeating duplicates.
19+
20+
---
21+
22+
## Script Details
23+
24+
| Field | Value |
25+
|-------|-------|
26+
| Table | N/A (JSON based) |
27+
| Type | Background Script |
28+
| Author | Sachin Narayanasamy |
29+
| Language | JavaScript (GlideRecord) |
30+
31+
---
32+
33+
## Logic Flow
34+
1. Define the JSON array of user details.
35+
2. Create an object to hold **unique users** and their roles.
36+
3. Loop through each JSON entry:
37+
- Trim and validate the title.
38+
- Add it to the user's array if it doesn’t already exist.
39+
4. Log each user and their unique roles.
40+
5. Display the total number of unique users.
41+
42+
---
43+
44+
## Example Output
45+
User: dennis.millar having Role(s): Account Exec Northeast
46+
User: ashley.parker having Role(s): Director
47+
User: steve.schorr having Role(s): Investigations Generalist
48+
User: tammie.schwartzwalde having Role(s): Senior Auditor, Payroll Generalist
49+
User: tommy.tom having Role(s): Tester
50+
Total unique users: 5

0 commit comments

Comments
 (0)