We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

getMyGroups() not working properly.

KS86
Tera Contributor

Hi all,

 

I am using getMyGroups() in my code to get all groups. It is returning one extra group. Why?

KS86_0-1766504083110.png

 

I know below thing can be achieved by other ways, but I want to use getMyGroups().

 

My code-

var groups = gs.getUser().getMyGroups();
var groupIds=JSON.parse(JSON.stringify(groups));
var gr=new GlideRecord('sys_user_group');
gr.addQuery('sys_id', 'IN', groupIds);
gr.query();

while(gr.next()){
    gs.info("Name "+gr.name)
}

Answer-
*** Script: Name HR Tier 1
*** Script: Name App Engine Admins
*** Script: Name Conditional Script Writer
*** Script: Name Team Development Code Reviewers
*** Script: Name HR
1 ACCEPTED SOLUTION

@KS86 Below will return expected output:

 

gs.getUser().getMyExplicitGroups()

View solution in original post

10 REPLIES 10

Reason is that getMyExplicitGroups() return arrayList and not array. Do try below code:

 

var groups = j2js(gs.getUser().getMyExplicitGroups());  // j2js is OOB SI to convert java to javascript obj.
var gr = new GlideRecord("sys_user_group");
gr.addQuery("sys_id","IN", groups);
gr.query();
while (gr.next()) {
   gs.info(gr.name);
}