Assistance Needed: Duplicate Timestamps in Email Notifications

Keang
Tera Contributor

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

 

Keang_0-1721137246205.png

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:

 

Keang_2-1721137523355.png

 

 

 

 

 

3 REPLIES 3

Slava Savitsky
Giga Sage

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?

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();
            }
        }
    }

 

Hi @Slava Savitsky 

I have figured it out the issue.  Thank you