Skip to content
Closed
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
13 changes: 13 additions & 0 deletions Core ServiceNow APIs/GlideSystem/getCurrentScopeName/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**getCurrentScopeName()** is a GlideSystem method to get the name of the current application scope. Following code can be used to get the name.

gs.info(gs.getCurrentScopeName());//prints rhino.global if ran in Global scope

Scope can be changed from the Application Scope Picker.

<img width="421" height="128" alt="Screenshot 2025-10-20 at 9 34 00 AM" src="https://github.com/user-attachments/assets/03b198a9-c689-4865-b68c-a397e1ea44ea" />

If ran in a private application scope the output will contain the name of the private application.

<img width="1308" height="130" alt="Screenshot 2025-10-20 at 9 35 12 AM" src="https://github.com/user-attachments/assets/761a0b03-3ebc-40fc-b518-d3dce0c691a8" />


Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gs.info(gs.getCurrentScopeName()); //prints the name of application scope.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**Get the complete hierarchy of the managers for a given user.**
This script uses a recursive function to fetch the complete list of managers for any given user. Consider the following example.
<img width="929" height="298" alt="Screenshot 2025-10-20 at 1 29 11 AM" src="https://github.com/user-attachments/assets/aeeb718c-e528-4ff7-b4e1-f3d5d9772791" />

In this example user Abel Tutor reports to Abraham Lincoln, Abrham reports to Adela Cervantsz, Adela reports to Aileen Mottern and so on.

In order to fetch this complete hierachy the getManagerHierachy script can be used. Here is the example of this script with output.
<img width="1394" height="635" alt="Screenshot 2025-10-20 at 1 34 36 AM" src="https://github.com/user-attachments/assets/32fa4369-9743-4335-854f-63bdaf20f6e4" />


Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//Recursive function to get the complete manager hierarchy
//Param 1: managerArray an Array to hold manager hierarchy
//Param 2: next is representing next person in the manager hierarchy
function getManagerHierarchy(managerArray, next) {
var glideRecord = new GlideRecord('sys_user');
if (glideRecord.get(next)) {//Check if there is a user record
managerArray.push(glideRecord.manager.name + '');//Add the user detail to the manager array
return getManagerHierarchy(managerArray, glideRecord.getValue('manager')); //Recursively call the same method to get the details of manager

} else {//No more manager found return the array to callling function
return managerArray.toString().split(',').join(" >> ").substring(0, managerArray.toString().split(',').join(" >> ").length-4);
}
}

var managerArray = [];
gs.info(getManagerHierarchy(managerArray, '22826bf03710200044e0bfc8bcbe5dec')); //Pass the sys_id of person here
Loading