Assistance Needed: Duplicate Timestamps in Email Notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 06:45 AM
Hello,
I’m encountering an issue where email notifications are displaying duplicate timestamps and approver name. Could someone please provide suggestions on how to print only one timestamp and approver name? Thank you
This Business Rule Script copies comments from the approval table to the change request.
(function executeRule(current, previous /*null when async*/ ) {
if (!current.sysapproval.isNil() && current.sysapproval.sys_class_name == 'change_request') {
var changeRequest = new GlideRecord('change_request');
if (changeRequest.get(current.sysapproval.sys_id)) {
var changeType = changeRequest.type.getDisplayValue(); // Assuming 'type' is the field holding change type
if (changeType.toLowerCase() === 'standard') {
changeRequest.comments = changeRequest.comments + "\n" + current.comments.getJournalEntry(-1);
changeRequest.update();
}
}
}
})(current, previous);
Here is the email template is on Change Request table:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 09:21 AM
In your business rule, when you retrieve comments from the approval record, they already contain the timestamp and the name of the user who added the comment. When you add that text as a new comment in the Change Request, you literally create a new comment. Therefore, the system adds a new timestamp and name on top of it.
There are at least two ways to avoid it:
Option 1: Remove the first line of text from the approval comment before adding it to the Change Request.
Option 2: Instead of adding approval comment text as a new comment to the Change Request, consider copying it directly on [sys_journal_field] table level where the values of all journal fields are actually stored.
But regardless of the approach you choose, I would be very much interested to know why you are implementing this? What is the business need for it?
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 10:53 AM
Hello @Slava Savitsky
Thank you for your suggestions. When a change request is approved or rejected, the approver must add a comment to the record. We want this comment to be included in the email notification generated from the change request table. I modified the script as following, but it is still creates duplicate timestamp and the approver name:
(function executeRule(current, previous /*null when async*/ ) {
if (!current.sysapproval.isNil() && current.sysapproval.sys_class_name == 'change_request') {
var changeRequest = new GlideRecord('change_request');
if (changeRequest.get(current.sysapproval.sys_id)) {
var changeType = changeRequest.type.getDisplayValue(); // Assuming 'type' is the field holding change type
if (changeType.toLowerCase() === 'standard') {
changeRequest.comments = current.comments.getJournalEntry(-1);
changeRequest.update();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 01:46 PM
I have figured it out the issue. Thank you