Why does the updated date not change after sending an email from within the incident?

Amanda Stoupa
Tera Guru

Why does the updated date not change after sending an email from within an incident? Our helpdesk often sends emails from within ServiceNow to our customers, but since the updated date doesn't change after sending an email, it's difficult to see when the incident was actually last updated. See example below:

I created an incident and posted an additional comment and it shows a date/time in the activity log of 2017-06-15 10:38:22. I then sent an email from within the incident and it shows in the activity log as being sent at 2017-06-15 10:42:34.

find_real_file.png

However, the Updated date still shows 2017-06-15 10:38:22.

find_real_file.png

Does anyone know how to fix this?

1 ACCEPTED SOLUTION

Hi Deepali,
Sachin was referring to a Business Rule, created on the sys_email table. However, I don't think forcing the Updated [sys_updated_on] field to update, instead of letting it update automatically is best practice.

I ended up copying sent email from the email client to the Additional comments, and then updating my notifications so don't send a duplicate of the previously sent email (I added filter condition: updated_by is not system). Since updating Additional comments updates the Updated [sys_updated_on] field, this solved my problem.

This is the Business Rule on the sys_email table I created to copy sent email from the email client to the Additional comments:

find_real_file.png

Script on Advanced tab:

copyComments();

function copyComments() {
    // Verify if the mail was sent from the mail client and not a Notification
    var headers = current.headers;
    var isMailClient = headers.search("X-ServiceNow-Source: EmailClient");
    
    if (isMailClient != -1) {
        var incident = new GlideRecord('incident');
        incident.addQuery('sys_id', current.instance);
        incident.query();
        // Copy the body of the email to the additional comments
        while(incident.next())
            {
            var str = '[code]' + current.body + '[/code]';
            var itsender = current.sys_created_by;
            incident.comments = "An email was sent by " + itsender + "\n\n" + str;
            incident.update();
        }
    }
}

 

Hopefully this helps!

View solution in original post

10 REPLIES 10

Deepali5
Tera Contributor

Where do you write the script?

Thank you

Hi Deepali,
Sachin was referring to a Business Rule, created on the sys_email table. However, I don't think forcing the Updated [sys_updated_on] field to update, instead of letting it update automatically is best practice.

I ended up copying sent email from the email client to the Additional comments, and then updating my notifications so don't send a duplicate of the previously sent email (I added filter condition: updated_by is not system). Since updating Additional comments updates the Updated [sys_updated_on] field, this solved my problem.

This is the Business Rule on the sys_email table I created to copy sent email from the email client to the Additional comments:

find_real_file.png

Script on Advanced tab:

copyComments();

function copyComments() {
    // Verify if the mail was sent from the mail client and not a Notification
    var headers = current.headers;
    var isMailClient = headers.search("X-ServiceNow-Source: EmailClient");
    
    if (isMailClient != -1) {
        var incident = new GlideRecord('incident');
        incident.addQuery('sys_id', current.instance);
        incident.query();
        // Copy the body of the email to the additional comments
        while(incident.next())
            {
            var str = '[code]' + current.body + '[/code]';
            var itsender = current.sys_created_by;
            incident.comments = "An email was sent by " + itsender + "\n\n" + str;
            incident.update();
        }
    }
}

 

Hopefully this helps!

Hey this worked for me almost. 

My incident now updates the date at which the email was sent which is great, but the Updated By field shows "system" instead of the "itsender" (Update By field should populate the last sender). 

Do you have an update for that? 

find_real_file.png

Updated By should be Nathan

The Business Rule is updating the ticket after the email is sent, so it's the "system" that is actually copying the email body to the incident. I don't believe there is a way to force it to run as the user.

However, I think you may be able to create a Flow (using Flow Designer) to do this instead of using a Business Rule. Flows can be set to run as the user or as system, so that may be your best bet. Good luck!

Thank you for getting back to my comment so quickly. I'll check on that to see if I can make that work there... Just seems silly this isn't apart of the OOB experience.