How to add email to the activity log

alexbin
Kilo Contributor

Hi all,

My inbound email action works with incoming email (email type = new) as follow:

- parse external ticket number from the subject string

- find (ticket.external_number = parsed number) and update SNow ticket using new GlideRecord object (because variable 'current' is not associated with the SNow ticket)

All works as expected.

The problem is: the incoming email is not displayed in the activity log, while outgoing emails for the ticket displayed correctly.

How to fix this?

As I understand, activity log displayed information from the system audit tables. Can I add all necessary information to the tables manually?

Or maybe update somehow the email record in the mailbox before it is processed to link the email with the target ticket and use 'current' to update the ticket...

Please help!

1 ACCEPTED SOLUTION

A script similar to this should do the trick:



(function(){


  //look for the 3rd-party tool Incident


  var gr = new GlideRecord("incident");


  if (gr.get("correlation_id", email.subject)){


      //found it so let's update the SN Incident


      gr.comments = "We found it - here is the contents of the new email:\n" + email.body_text;


      //...whatever else you want to update would go here


      gr.update();


  } else {


      //did not find it so we need to create a new Incident


      gr.newRecord();


      gr.correlation_id = email.subject;


      gr.correlation_display = "Name of 3rd-Party Tool";


      gr.description = email.body_text;


      //...whatever else you want to update would go here


      gr.insert();


  }



  //now update the email record so it will show up in the record's activity formatter


  sys_email.target_table = "incident";


  sys_email.instance = gr.getValue("sys_id");


  sys_email.update();



})();



Obviously things would need to be tweaked a bit to fit your use case, such as retrieving the 3rd-party's incident number, etc...     I setup the Inbound Email Action with the following assumptions/criteria:


  • the emails that come in are always new ones, not replies to a SN email, so they would never have a watermark in them
  • the subject of the email contains only the 3rd-party tool's incident number
  • the 3rd party tool's incident number is saved in the "correlation_id" field
  • the emails are coming in from a particular user record or email address (I set mine to look for my user/email address)
  • once this script is run, we can skip the other Inbound Email Actions ("Stop processing" is checked)
  • set to run on the "Email [sys_email]" table so the "current" objet does not waste a new Incident number each time it is run
  • set to run early ("Order" = 10)
  • running on the Geneva version


find_real_file.png



This way the "integration" is neatly wrapped up in just 1 record.


View solution in original post

14 REPLIES 14

rob_pastore
ServiceNow Employee
ServiceNow Employee

in that case, you should be able to do this before




anotherTicketObject.get('external_number', ...);


anotherTicketObject.comments = email.body;


anotherTicketObject.update();


of course, it was not complete script, I update several fields of the ticket between 'get()' and 'update()'


I'm afraid, the system tracks updates in the 'current' only.


Chuck Tomasi
Tera Patron

Hi Alex,



Since you can see outgoing, I assume that you have Sent/Received emails displayed in the activity formatter turned on, correct?



Activity formatter


Hi Chuck,



Yes, the activity formatter turned on and configured properly.



I think, the system can't match the email with the ticket, no watermark/SNow number are present in the message, only external number (I store external number in my custom field to match external tickets with SNow tickets).



Regards,


Alex


Jim Coyne
Kilo Patron

I'm assuming the "Target table" and "Target" fields on your incoming emails are blank, correct?   You could try updating them from within your Inbound Email Action.   You can access the mail record using the "sys_email" variable - Accessing Email Record from Inbound Email Actions.   The "Target table" would be "incident" and "Target" would be the sys_id of the Incident record.