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.

How to get group users mail id dynamically

Tamil5
Tera Expert

Hi Friends,

I need to send a mail notification to some mail groups dynamically based on the condition.

I am not ready to create a mail id for my group.

But I need to get the mail ids of the group members.So that I can send them notification.

How to achieve this.Please advice

Thanks

Prici

1 ACCEPTED SOLUTION

Tamil5
Tera Expert

Thanks everyone for your time.


The following snippets did it..



var groupMemberMailIds = '';


var gr = new GlideRecord('sys_user_grmember');


gr.addQuery('group.name','<group-name>');


gr.query();



while(gr.next()){


  if(groupMemberMailIds != ''){


  groupMemberMailIds += ',' + gr.user.email;


  }else{


  groupMemberMailIds = gr.user.email;


  }


}


gs.log(' groupMemberMailIds are.....'+groupMemberMailIds);




Thanks


Chitra


View solution in original post

6 REPLIES 6

Tamil5
Tera Expert

Thanks everyone for your time.


The following snippets did it..



var groupMemberMailIds = '';


var gr = new GlideRecord('sys_user_grmember');


gr.addQuery('group.name','<group-name>');


gr.query();



while(gr.next()){


  if(groupMemberMailIds != ''){


  groupMemberMailIds += ',' + gr.user.email;


  }else{


  groupMemberMailIds = gr.user.email;


  }


}


gs.log(' groupMemberMailIds are.....'+groupMemberMailIds);




Thanks


Chitra


Hello Tamil,

Can you share the script. Is this a catalog client script or runscript? I have a similar requirement. I need to trigger email to group members when RITM state is changed. Can you help me with providing the script you wrote?