The CreatorCon Call for Content is officially open! Get started here.

I want to display the hierarchical structure of a group in a cool and beautiful tree form.

Community Alums
Not applicable

I want to display the hierarchical structure of a group in a cool and beautiful tree form. (tree picker was not good enough)
If possible, it would be great if I could also see the members connected to the group at a glance!
I  want to utilize generic_hierarchy after looking at the following page, but for some reason I get an error.
What I want to do is to graphically represent the parent-child hierarchy of groups.
If you can achieve that in your report, please let me know how to do that as well!

 

https://www.servicenow.com/community/platform-analytics-forum/visualize-group-hierarchy/m-p/1219909

I am asking because I have been checking and trying as much as I can on the community postings and it is not working.

1 ACCEPTED SOLUTION

Community Alums
Not applicable

It has solved itself and I am putting the script on here, although there is still room for improvement.

UI Action
Show update:true
Form link:True
Action name:GroupHierarchy

var currentGroupId = current.getValue('sys_id');

var parentGroupId = findTopParentGroup(currentGroupId);
function findTopParentGroup(groupId) {
    var gr = new GlideRecord('sys_user_group');
    if (gr.get(groupId)) {
        while (gr.getValue('parent')) {
            gr.get(gr.getValue('parent'));
        }
        return gr.getValue('sys_id'); 
    }
    return null; 
}

if (parentGroupId) {

    var url = "generic_hierarchy.do";
    url += "?sysparm_stack=no";
    url += "&sysparm_attributes=record=sys_user_group,";
    url += "parent=parent,";
    url += "title=name,";
    url += "description=manager,";
    url += "baseid=" + parentGroupId; 
    
    gs.setRedirect(url);
} else {
    gs.addErrorMessage("Top parent group not found.");
}

 

View solution in original post

3 REPLIES 3

Mark Manders
Mega Patron

There is no OOB way to do this in ServiceNow. 

Next to that: why are you posting the same question in the same forum twice, using 2 accounts? You are wasting time of people trying to help you and don't know what solution was already provided.


https://www.servicenow.com/community/developer-forum/i-want-to-display-the-group-hierarchy-in-a-cool...


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Community Alums
Not applicable

I accidentally posted it on one account and immediately deleted it, but I guess I didn't delete it.
I am sorry for taking up your and everyone's valuable time.

Community Alums
Not applicable

It has solved itself and I am putting the script on here, although there is still room for improvement.

UI Action
Show update:true
Form link:True
Action name:GroupHierarchy

var currentGroupId = current.getValue('sys_id');

var parentGroupId = findTopParentGroup(currentGroupId);
function findTopParentGroup(groupId) {
    var gr = new GlideRecord('sys_user_group');
    if (gr.get(groupId)) {
        while (gr.getValue('parent')) {
            gr.get(gr.getValue('parent'));
        }
        return gr.getValue('sys_id'); 
    }
    return null; 
}

if (parentGroupId) {

    var url = "generic_hierarchy.do";
    url += "?sysparm_stack=no";
    url += "&sysparm_attributes=record=sys_user_group,";
    url += "parent=parent,";
    url += "title=name,";
    url += "description=manager,";
    url += "baseid=" + parentGroupId; 
    
    gs.setRedirect(url);
} else {
    gs.addErrorMessage("Top parent group not found.");
}