How to get all group names from sys_user_grmember table through client scripts.

Navya8
Kilo Contributor

Hello,

I have tried getting group names from the sys_user_grmember table by querying through email of user.

However, I am getting sysids of groups of a user. 

I have used the following client script.

Thanks in advance 

Navya

..................Client Script.....................................................................

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var groups = [];

var gr = new GlideRecord('sys_user_grmember');


gr.addQuery('user.email', g_form.getValue('email'));
gr.query();


while (gr.next())
{
groups.push(gr.group);
}
alert(groups);

1 ACCEPTED SOLUTION

Hi,

please use while(gr.next()) instead of if(gr.next())

Regards
Ankur

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

View solution in original post

6 REPLIES 6

Hi,

Thanks for the update

Regards
Ankur

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

Hi,

please use while(gr.next()) instead of if(gr.next())

Regards
Ankur

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