How to send a notification after the approval is rejected or selected

avinashdubey103
Tera Guru

hi ,

 

I have a request to send  2 notification to requester , 
1st , when is approval is rejected , 2nd when is approval is approved

how can i achieve this ?

 

9 REPLIES 9

Hi @avinashdubey103 ,

 

Can you please let me know for which table records u r planning to modify the content please so that it would be easy for me to provide you the answer.

 

Thanks,

Danish

 

Sayali Gurav
Tera Guru
Tera Guru

Create a Business Rule:

- Navigate to System Definition > Business Rules in your ServiceNow instance.
- Create a new Business Rule, for example, Send Approval Notification.

Configure the Business Rule:

- Set the When to run condition. In this case, it would be when the approval_status field changes.
- Set the Advanced field to run on the u_approval_table table.

Write the Script:

(function executeRule(current, previous ) {
// Check if the approval status is 'rejected' or 'selected'
var approvalStatus = current.approval_status;

if (approvalStatus == 'rejected' || approvalStatus == 'selected') {
// Define the notification message
var notificationMessage = "Approval status changed to: " + approvalStatus;

// Create a GlideEmailOutbound object
var email = new GlideEmailOutbound();

// Define email parameters
email.setSubject("Approval Status Change");
email.setBody(notificationMessage);
email.addTo("recipient@example.com"); // Specify the recipient email address

// Send the email
email.send();
}
})(current, previous);

Link the Script to the Business Rule:

- In the Business Rule configuration, set the Script field to the script you've written.

Workflow:

- Update an approval record in u_approval_table to have a status of 'rejected' or 'selected'. This should trigger the Business Rule, which will in turn send an email notification

 

Mark my answer helpful or correct id applicable.

Thanks & Regards,

Sayali Gurav

Hi , thanks for reply 

i want to send this email to requested for 

You can try this :

(function executeRule(current, previous ) {
// Check if approval is rejected
if (current.state == 'rejected') {
gs.eventQueue('send.rejected.notification', current, current.requested_for);
} else if (current.state == 'approved') {
gs.eventQueue('send.approved.notification', current, current.requested_for);
}
})(current, previous);

 

Mark my answer helpful or correct id applicable.

Thanks & Regards,

Sayali Gurav

Sneha Veerabath
Tera Expert

Hi @avinashdubey103,

You can also use flow designer for this, steps to follow:

1. Create the flow for the required table 

2. Use the action "Ask For Approval"

3. Using the above send emails when it is approved or rejected.

 

Please mark Helpful and Correct if it really helped you.

Regards,

Sneha V