From 56aef891550de6be230a108842f04680e10e74cf Mon Sep 17 00:00:00 2001 From: Noah-Drew Date: Sat, 18 Oct 2025 20:45:09 -0400 Subject: [PATCH 1/2] Create GetAllChildRolesRecursive.js --- .../GetAllChildRolesRecursive.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Get All Child Roles/GetAllChildRolesRecursive.js diff --git a/Server-Side Components/Background Scripts/Get All Child Roles/GetAllChildRolesRecursive.js b/Server-Side Components/Background Scripts/Get All Child Roles/GetAllChildRolesRecursive.js new file mode 100644 index 0000000000..faa52e94b5 --- /dev/null +++ b/Server-Side Components/Background Scripts/Get All Child Roles/GetAllChildRolesRecursive.js @@ -0,0 +1,49 @@ +// You can set this to a role name or the Sys ID of the "sys_user_role" record +var roleNameOrSysId = "itil"; +var result = getFullRoleHierarchyList(roleNameOrSysId); + +// This is just to print out the results. Remove this when you want to use it +for (var i = 0; i < result.length; i++) { + gs.info(result[i]); +} + +function getFullRoleHierarchyList(roleNameOrSysID) { + + var roleSysID = ""; + var grRole = new GlideRecord("sys_user_role"); + grRole.addEncodedQuery("name=" + roleNameOrSysID + "^ORsys_id=" + roleNameOrSysID); + grRole.query(); + while(grRole.next()) { + roleSysID = grRole.getUniqueValue(); + } + + if (!roleSysID) { + gs.warn("Role entered does not exist.") + return; + } + + var obj = getChildRoles({}, roleSysID, "", "role", "contains"); + var arr = []; + for (var key in obj) { + arr.push(obj[key].display); + } + return arr; +} + +function getChildRoles(found, queryId, display, queryField, getField) { + if (!queryId || found.hasOwnProperty(queryId)) + return; + + if (display) { + found[queryId] = {display: display}; + direct = false; + } + var gr = new GlideRecord("sys_user_role_contains"); + gr.addEncodedQuery(queryField + "=" + queryId); + gr.query(); + while(gr.next()) { + getChildRoles(found, gr.getValue(getField), gr.getDisplayValue(getField), queryField, getField); + } + + return found; +} From 9842f77ded68b15fdac968bc175eba5fe3c425a8 Mon Sep 17 00:00:00 2001 From: Noah-Drew Date: Sat, 18 Oct 2025 20:54:56 -0400 Subject: [PATCH 2/2] Create README.md --- .../Get All Child Roles/README.md | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Get All Child Roles/README.md diff --git a/Server-Side Components/Background Scripts/Get All Child Roles/README.md b/Server-Side Components/Background Scripts/Get All Child Roles/README.md new file mode 100644 index 0000000000..bcf70b6d0d --- /dev/null +++ b/Server-Side Components/Background Scripts/Get All Child Roles/README.md @@ -0,0 +1,76 @@ +Use this script to get a flattened array of all Roles contained by a specificed role. +This will recursively drill down into other contained roles so you have the full list of roles involved in the hierarchy. + +To use, you can set the "roleNameOrSysId" variable to either a role name or the Sys ID from the "sys_user_role" table +Or call the "getFullRoleHierarchyList" function directly and pass in a role name or Sys ID + +The following lines exist just to print out the results for your testing. Remove this if needed: + +for (var i = 0; i < result.length; i++) { + gs.info(result[i]); +} + + + +- Example input: "it_project_manager" + +- List of chiold roles found in the Related List for "it_project_manager": + +resource_user +idea_manager +it_demand_manager +pa_viewer +it_project_user +project_manager +timeline_user + +- Example output and full list of nested child roles for "it_project_manager": + +resource_user +report_group +report_user +viz_creator +skill_user +idea_manager +it_demand_manager +it_project_user +it_project_portfolio_user +project_portfolio_user +sn_gf.goal_user +sn_gf.goal_user_read +sn_gf.strategy_planner_read +it_demand_user +demand_user +baseline_user +pps_resource +project_user +timecard_user +sn_test_management.tester +planning_console_user +task_editor +sn_gf.strategy_planner +timeline_user +demand_manager +scrum_user +cmdb_read +scrum_admin +rm_scrum_task_admin +rm_doc_admin +rm_task_admin +rm_test_admin +rm_story_admin +rm_epic_admin +rm_release_scrum_admin +rm_sprint_admin +view_changer +financial_mgmt_user +fiscal_calendar_user +sn_invst_pln.std_user +rate_model_user +sn_invst_pln_v2.investment_user +sn_invst_pln_investment_user +currency_instance_report_admin +pa_viewer +project_manager +timecard_approver +sn_test_management.test_manager