From d9268531cf7228d5385e62403020d03f5f14b76e Mon Sep 17 00:00:00 2001 From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com> Date: Thu, 2 Oct 2025 21:51:49 +0530 Subject: [PATCH 1/5] extractValueFromJSON.js This script helps to extract data from the JSON and show the username and corresponding role(s) --- .../extractValueFromJSON.js | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Extract Value from JSON/extractValueFromJSON.js diff --git a/Server-Side Components/Background Scripts/Extract Value from JSON/extractValueFromJSON.js b/Server-Side Components/Background Scripts/Extract Value from JSON/extractValueFromJSON.js new file mode 100644 index 0000000000..0af1c32d98 --- /dev/null +++ b/Server-Side Components/Background Scripts/Extract Value from JSON/extractValueFromJSON.js @@ -0,0 +1,46 @@ +//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(", ")); +} From 6a97c4ec41777cf53d274d28579f41615b742627 Mon Sep 17 00:00:00 2001 From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com> Date: Thu, 2 Oct 2025 22:00:46 +0530 Subject: [PATCH 2/5] readme.md --- .../Extract Value from JSON/readme.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Extract Value from JSON/readme.md diff --git a/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md b/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md new file mode 100644 index 0000000000..106b3d67ee --- /dev/null +++ b/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md @@ -0,0 +1,15 @@ +Open 'Scripts - background' and run the script of [extractValueFromJSON.js] file. + +This is generally utilized in integrations when we receive the JSON response and we have to get the value from it. + + +Script: + +image + + +Result: + +image + + From b2f501dcf5dadba4e7ba0a7640c4d9021e99c692 Mon Sep 17 00:00:00 2001 From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com> Date: Thu, 2 Oct 2025 22:11:54 +0530 Subject: [PATCH 3/5] readme.md --- .../Background Scripts/Extract Value from JSON/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md b/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md index 106b3d67ee..73662608fe 100644 --- a/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md +++ b/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md @@ -1,6 +1,6 @@ Open 'Scripts - background' and run the script of [extractValueFromJSON.js] file. -This is generally utilized in integrations when we receive the JSON response and we have to get the value from it. +This also checks for the duplicate user_name and shows the unique ones and the corresponding roles of that particular user. Script: From a4fa5638fe4d706fc268ed814eab5256967bb4b6 Mon Sep 17 00:00:00 2001 From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com> Date: Fri, 3 Oct 2025 13:25:11 +0530 Subject: [PATCH 4/5] extractValueFromJSON.js This script comes handy to extract the value from a JSON object and also to tackle with the duplicate 'user_name' and shows the corresponding title related to that particular 'user'. --- .../Extract Value from JSON/extractValueFromJSON.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Server-Side Components/Background Scripts/Extract Value from JSON/extractValueFromJSON.js b/Server-Side Components/Background Scripts/Extract Value from JSON/extractValueFromJSON.js index 0af1c32d98..d978d115bf 100644 --- a/Server-Side Components/Background Scripts/Extract Value from JSON/extractValueFromJSON.js +++ b/Server-Side Components/Background Scripts/Extract Value from JSON/extractValueFromJSON.js @@ -28,6 +28,7 @@ var userData = { ] }; + var userRoles = {}; for (var i = 0; i < userData.userDetails.length; i++) { var user = userData.userDetails[i]; From 804df8f32e7b191a954763c3e959f17b5c8bf992 Mon Sep 17 00:00:00 2001 From: SrijanPatwa <148682493+SrijanPatwa@users.noreply.github.com> Date: Fri, 3 Oct 2025 13:27:36 +0530 Subject: [PATCH 5/5] readme.md This script comes handy to extract the value from a JSON object and also to tackle with the duplicate 'user_name' to only show the unique ones and display the corresponding title related to that particular 'user'. --- .../Background Scripts/Extract Value from JSON/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md b/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md index 73662608fe..25089f2b8d 100644 --- a/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md +++ b/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md @@ -1,4 +1,4 @@ -Open 'Scripts - background' and run the script of [extractValueFromJSON.js] file. +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.