- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 03:59 AM
Hi,
In my requirement i should send email to particular members in a group , but not for all members.
can someone help on how to achieve this.
Regards,
Kalyani
Solved! Go to Solution.
- Labels:
-
Notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 05:04 AM
Hi
You can achieve this using a Notification Email Script and use the code as below which will check if users of the group are belonging to same portfolio or not and will trigger accordingly as you require:
.
Use the Script as below:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var getUserRoleGroup = current.FieldName; //Replace "FieldName" with your Field i.e.User Role Group
var port = current.FieldName; //Replace "FieldName" with your Field i.e.Portfolio
var getGroupMembers = fetchGroupMembers(getUserRoleGroup);
var getUserDetails = validateUser(getGroupMembers,port);
function fetchGroupMembers(groupID){
var arr = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',groupID);
gr.query();
while(gr.next()){
arr.push(gr.user.toString());
}
return arr.toString();
}
function validateUser(users,port){
var splitUsers = users.split(',');
for(var i =0;i<splitUsers.length;i++){
var checkPortfolio = validatePortfolio(splitUsers[i]);
}
}
function validatePortfolio(userID,port){
var gr1 = new GlideRecord('sys_user');
gr1.addQuery('sys_id',userID);
gr1.query();
if(gr1.next()){
if(gr1.FieldName == port){
email.setReplyTo(gr1.email.toString());
}
}
}
})(current, template, email, email_action, event);
Now call this Notification Script in your Notification body with below syntax as below:
${mail_script:Mail Script Name}
Just replace the field names in script above and let me know if you are stuck.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2022 12:51 AM
Hi kalyani, Please mark my responses as helpful and correct, if I have answered your question.
Thanks
Regards
Sulabh Garg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 05:04 AM
Hi
You can achieve this using a Notification Email Script and use the code as below which will check if users of the group are belonging to same portfolio or not and will trigger accordingly as you require:
.
Use the Script as below:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var getUserRoleGroup = current.FieldName; //Replace "FieldName" with your Field i.e.User Role Group
var port = current.FieldName; //Replace "FieldName" with your Field i.e.Portfolio
var getGroupMembers = fetchGroupMembers(getUserRoleGroup);
var getUserDetails = validateUser(getGroupMembers,port);
function fetchGroupMembers(groupID){
var arr = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',groupID);
gr.query();
while(gr.next()){
arr.push(gr.user.toString());
}
return arr.toString();
}
function validateUser(users,port){
var splitUsers = users.split(',');
for(var i =0;i<splitUsers.length;i++){
var checkPortfolio = validatePortfolio(splitUsers[i]);
}
}
function validatePortfolio(userID,port){
var gr1 = new GlideRecord('sys_user');
gr1.addQuery('sys_id',userID);
gr1.query();
if(gr1.next()){
if(gr1.FieldName == port){
email.setReplyTo(gr1.email.toString());
}
}
}
})(current, template, email, email_action, event);
Now call this Notification Script in your Notification body with below syntax as below:
${mail_script:Mail Script Name}
Just replace the field names in script above and let me know if you are stuck.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke