Sys Id not being picked up in isMemberOf function

SN Rookie
Giga Expert

Hi,

My below script is no getting executed when I put in the sys id of an assignment group. It works fine when I use the gropu name.

g_scratchpad.grp = gs.getUser().isMemberOf('Incident-Management_INCPRBCAT');

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

The isMemberOf() function takes group name and not sys_id. check the link below

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=GUser-isMemberOf_S

Mark Correct if this solves your issue and also mark 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

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

The isMemberOf() function takes group name and not sys_id. check the link below

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=GUser-isMemberOf_S

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

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

How can we use the sys ID instead because group names can change in future thus breaking the functionality?

Hi,

As of now that won't be possible using isMemberOf() unless ServiceNow changes the function definition.

you need to query sys_user_grmember table with that user id and group sys_id, that is the only way as of now

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

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

GeoffreyOptumOp
Tera Expert

Good news.  In ROME, you can pass in a Group Name OR a Sys_Id, and it will work either way.

Make sure that the GROUP you are searching for is ACTIVE, otherwise the function will return false even though the user actually IS a member.  This is very confusing.

https://community.servicenow.com/community?id=community_question&sys_id=b43fe555db56e410a08a1ea66896192f