How to send a notification after the approval is rejected or selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 09:06 PM
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 10:32 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 09:58 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 10:59 PM
Hi , thanks for reply
i want to send this email to requested for
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 11:16 PM - edited 10-17-2023 11:17 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2023 11:18 PM
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