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..d978d115bf --- /dev/null +++ b/Server-Side Components/Background Scripts/Extract Value from JSON/extractValueFromJSON.js @@ -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(", ")); +} 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..25089f2b8d --- /dev/null +++ b/Server-Side Components/Background Scripts/Extract Value from JSON/readme.md @@ -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: + +image + + +Result: + +image + +