Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//JSON of username and corresponding title

var userData = {
"userDetails": [{
"user_name": "dennis.millar",
"title": "Account Exec Northeast"
},
{
"user_name": "ashley.parker",
"title": "Director"
},
{
"user_name": "steve.schorr",
"title": "Investigations Generalist"
},
{
"user_name": "tammie.schwartzwalde",
"title": "Senior Auditor"
},
{
"user_name": "tammie.schwartzwalde",
"title": "Payroll Generalist"
},
{
"user_name": "tommy.tom",
"title": "Tester"
},
]
};


var userRoles = {};
for (var i = 0; i < userData.userDetails.length; i++) {
var user = userData.userDetails[i];
if (!userRoles[user.user_name]) {
userRoles[user.user_name] = [];
}

if (userRoles[user.user_name].indexOf(user.title) === -1) {
userRoles[user.user_name].push(user.title);
}
}


for (var userName in userRoles) {
gs.info("User: " + userName + " having Role(s): " + userRoles[userName].join(", "));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Open 'Scripts - background' in ServiceNow and run the script of [extractValueFromJSON.js] file.

This also checks for the duplicate user_name and shows the unique ones and the corresponding roles of that particular user.


Script:

<img width="556" height="636" alt="image" src="https://github.com/user-attachments/assets/8300e272-a712-4b4d-bf91-6e2d8df0aa6b" />


Result:

<img width="937" height="167" alt="image" src="https://github.com/user-attachments/assets/51ed18d3-ec65-4812-9298-0fc43bd7bec6" />


Loading