Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get all users from group

kiranped
Giga Contributor

Hi All,

Is there any js-function to get the user list object by group-name or is there any script to get all users from a group?

example group name is: IS&T Senior Leadership Team

Thanks & Regards,

Kiran Pedduri

1 ACCEPTED SOLUTION

Hi Kiran,



Sorry, I had an error in the first one. I was pushing the sys_id of the membership record, not the users. I've corrected it.



Easy change... You can 'dot-walk' to get that. If you want the user_name field (labeled User ID, like chuck.tomasi) you can change the answer.push() line to this



answer.push(mem.user.name.toString()).



You want the email,answer.push(mem.user.email.toString());


View solution in original post

22 REPLIES 22

Got it   thank you


Can I know why the same is not working to open group chat, please find the macro code as below,please suggest




<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);"/>


<j:set var="jvar_n" value="show_incidents_${jvar_guid}:${ref}"/>


<g:reference_decoration id="${jvar_n}" field="${ref}"


onclick="invokeChat('${ref}');"


title="Invoke Chat1" image="lync.jpg"/>


<script>


function invokeChat(reference) {


var s = reference.split('.');


var tableName = s[0];


var referenceField = s[1];


var v = g_form.getValue(referenceField);


var emails = [];


var mem = new GlideRecord('sys_user_grmember');


mem.addQuery('group.name', 'v');


mem.query();


while (mem.next()){


emails.push(mem.user.email);


}


var i = emails.length;


while(i-1){


var url = 'sip:' + emails[i];


var w = getTopWindow();


w.open(url);


}


}


is variable v contains sys_id or name,



if it has sys_id then use:


mem.addQuery('group', v); //Remove quotes from v



if it contains group name then use,


mem.addQuery('group.name', v); //Remove quotes from v


Hi Shishir, OK. it is working fine . Can i know how to open group chat as i opened here single window by using "var w = getTopWindow();' but how to open group window is there any property for that




<g:evaluate var="jvar_guid" expression="gs.generateGUID(this);"/>


<j:set var="jvar_n" value="show_incidents_${jvar_guid}:${ref}"/>


<g:reference_decoration id="${jvar_n}" field="${ref}"


onclick="invokeChat('${ref}');"


title="Invoke Chat1" image="lync.jpg"/>


<script>


function invokeChat(reference) {


var s = reference.split('.');


var tableName = s[0];


var referenceField = s[1];


var v = g_form.getValue(referenceField);


var emails = [];


var mem = new GlideRecord('sys_user_grmember');


mem.addQuery('group.name', v);


mem.query();


while (mem.next()){


emails.push(mem.user.email);


}


var i = emails.length;


while(i-1){


var url = 'sip:' + emails[i];


var w = getTopWindow();


w.open(url);


}


}


Saikiran Gudur1
Mega Guru

Hi Kiran,



You can use the 'sys_user_grmember' table for that.




Just like this:-



var grMembr = new GlideRecord('sys_user_grmember');


grMembr.addQuery('name','IS&T Senior Leadership Team');


grMembr.query();




This will give your desired records you can iterate through them to implement your desired functionality.



please mark my reply as "Helpful/Correct Answer" Or Like if helpful.



Regards,


Saikiran Guduri.


sp_18
Giga Contributor

Hi ,



Can anyone tell me how to get the list of watch list members and display the


first name of watch list member.




in email template as- Dear "insert first name of watch list member",



*** this is the code i have but its wrong as watch list members are multiple



(function executeRule(current,previous){



var gr = new GlideRecord("u_support_management");


gr.addQuery('active',true);


      gr.query();


              if (gr.next()) {


              var firstName= gr.watch_list.first_name.getDisplayValue();          


                              template.print(firstName);


     


                            }


      return '';


})(current,previous);




Thank You,