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

Jace Benson
Mega Sage

The email doesn't update the incident.   What you are seeing in the activity is an email was sent, and its details.   You could add a business rule to update the incident, but you'd want to be sure to do and gliderecord update with setWorkflow(false) to stop it from causing an infinite loop (imagine sending an email, it updates the incident, incident was updated so it sent an email, incident updated, ... )


sachin_namjoshi
Kilo Patron
Kilo Patron

You can write below below rule as workaround.



Table: Email [sys_email]


When = After


Insert and Update Checked


Condition:


current.type == 'sent' && current.headers.indexOf('X-ServiceNow-Source: EmailClient') > -1



Script:



function onAfter(current, previous) {


    //This function will be automatically called when this rule is processed.


var record = new GlideRecord(current.target_table);


//Grab the email message that matches the record


record.addQuery('sys_id', current.instance);


record.query();


if (record.next()) {


record.sys_updated_on = gs.getNowDateTime();


  record.update();


  }


}



Regards,


Sachin


Hi Sachin,
Thank you for the suggestion. I'll give it a try and see if it meets our needs.



PS: I still don't understand why ServiceNow wouldn't build this basic functionality into the system. What is the difference between posting a response and having it send an email to the user from the incident and just sending an email to the user from the incident. Process-wise, those are basically the same thing. I know ServiceNow hates email, but still...


Put in a enhancement request on HI to ask them to do this.