Notification to group - notifying each member in the group with their name in the email body

Tanya Manoj
Tera Contributor

Hi community!

 

we are currently using a custom table (say test table) that extends task table and when certain conditions are met, there will be a group approval record created for our test table record and when any user in the group approves it, the other approvals will be set to no longer required. now, our new requirement is that when any of the user in this group approves or rejects the task, then there should be an email sent for the users.

How to configure this notification? I was thinking of creating notification on sysapproval_approver table when source table is test table and approval record state changes to approved or rejected, then the group will be receiving notifications but problem with this is that how do I set the approver name dynamically in the email body?

(This mail should be sent to all the users in the group, say user1, user2, user3 and in the email body there should be something like dear user1, dear user2... How do I set these user names in body dynamically?)

 

2 ACCEPTED SOLUTIONS

Sebas Di Loreto
Kilo Sage
Kilo Sage

@Tanya Manoj 

It seems you are close to getting the solution you need.

I think you should use an email script for what you want.

Take a look at this out of the box example: /sys_script_email.do?sys_id=65451214532310101553ddeeff7b128d

 

SebastianDL_0-1671544193664.png

 

Then you call that email script from you notification body with ${mail_script:<your script>}

 

SebastianDL_1-1671544354851.png

 

 


If I helped you with your case, please click the Thumb Icon and mark as Correct.


View solution in original post

jaheerhattiwale
Mega Sage
Mega Sage

@Tanya Manoj For adding Approver name to email body you can use Approver field of "sysapproval_approver" table as below

jaheerhattiwale_0-1671546461317.png

 

Create an event

We will use gs.eventQueue() function to send notification to each user.

And you can add following script to the business rule

 

var groupMemeber = new GlideRecord("sys_user_grmember");
groupMemeber.addQuery("group.name=<YOUR GROUP NAME HERE>");
groupMemeber.query();

while(groupMemeber.next()){
    var param = {
        "approver_name" : current.approver.getDisplayValue(),
        "group_memeber_name": groupMemeber.user.getDisplayValue();
    }

    gs.eventQueue("<EVENT CREATED>", current, groupMemeber.user.toString(), param);
}
 
Create a notification
It should trigger when the event created is fired
Check event param1 contains recipient
 
in the body you can add
 
Dear event.param2.group_memeber_name,
 
approved by event.param2.approver_name
 
Please mark as correct answer if this solves your issue.

 

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

4 REPLIES 4

Sebas Di Loreto
Kilo Sage
Kilo Sage

@Tanya Manoj 

It seems you are close to getting the solution you need.

I think you should use an email script for what you want.

Take a look at this out of the box example: /sys_script_email.do?sys_id=65451214532310101553ddeeff7b128d

 

SebastianDL_0-1671544193664.png

 

Then you call that email script from you notification body with ${mail_script:<your script>}

 

SebastianDL_1-1671544354851.png

 

 


If I helped you with your case, please click the Thumb Icon and mark as Correct.


jaheerhattiwale
Mega Sage
Mega Sage

@Tanya Manoj For adding Approver name to email body you can use Approver field of "sysapproval_approver" table as below

jaheerhattiwale_0-1671546461317.png

 

Create an event

We will use gs.eventQueue() function to send notification to each user.

And you can add following script to the business rule

 

var groupMemeber = new GlideRecord("sys_user_grmember");
groupMemeber.addQuery("group.name=<YOUR GROUP NAME HERE>");
groupMemeber.query();

while(groupMemeber.next()){
    var param = {
        "approver_name" : current.approver.getDisplayValue(),
        "group_memeber_name": groupMemeber.user.getDisplayValue();
    }

    gs.eventQueue("<EVENT CREATED>", current, groupMemeber.user.toString(), param);
}
 
Create a notification
It should trigger when the event created is fired
Check event param1 contains recipient
 
in the body you can add
 
Dear event.param2.group_memeber_name,
 
approved by event.param2.approver_name
 
Please mark as correct answer if this solves your issue.

 

 

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

Tanya Manoj
Tera Contributor

Thanks @Sebas Di Loreto & @jaheerhattiwale ,

I have done it using mail scripts and the other solution worked for me too. 

Thanks for helping!

👍

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023