How to getMyGroups in scoped application

Komal_D
Kilo Contributor

Hi,

How to get my all groups in scoped application.

I am getting error below

Server JavaScript error Cannot find function getMyGroups in object com.glide.script.fencing.ScopedUser@1ac4a90.

 

I am writing an encoded query to get my group is there any way to solve above error and get my groups.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Komal,

Have this custom function to get the groups for the user:

var uID = gs.getUserID();

var groupArr = [];

var grmember = new GlideRecord('sys_user_grmember');
   grmember.addQuery('user', uID);
   grmember.addQuery('group.active', true);
   grmember.query();
   while(grmember.next()){
      //Push the group sys_id values into the group array
      groupArr.push(grmember.group.toString());
   }

the array when you print will tell you the groups to which user belongs.

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Hi Ankur, 

How do I get all the users from those list of groups (groupsArr) 

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

The getMyGroups() has been fixed in the new Madrid Patch 6, so now it should work fine also in scoped applications,

Please refer to the PRB1347170 (https://docs.servicenow.com/bundle/madrid-release-notes/page/release-notes/quality/madrid-patch-6.ht...)

If I have answered your question, please mark my response as correct and/or helpful so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.

Thank you

Cheers
Alberto

We just upgraded to patch 6 over the weekend. getMyGroups doesn't even seem to be supported at all from scoped gs.getUser().getMyGroups()... Though I do see in the related problem where it calls it out.

 

https://docs.servicenow.com/bundle/madrid-application-development/page/app-store/dev_portal/API_refe...

 

It contains isMemeberOf, but that is it.

 

On top of this issue, I was hoping to us (Dynamic) encoded query, but that is also not supported from scoped applications, ug.

Well that sucks... I got all excited about Alberto's comment and patch 6 (we're currently on 4b of Madrid), only to hear your story.  😞

Yeah, that link you provided doesn't mention getMyGroups().  <sigh>...

Is anyone else running patch 6 or greater for Madrid and successfully using gs.getUser().getMyGroups() in a scoped app?