We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Retrieve sender's mail ID from escalation mail and populate in incident form.

GnaneshwaraP
Tera Contributor

I have a task where, when an user escalates an incident to "escalations@abc.com", I need to get the sender's email address from the mail and and populate the value in "sender mail" field of the incident form. 

 

I don't have any idea to implement this. I was advised to create an Inbound email action and test this by creating an email record directly into the 'sys_email' table. Is this a correct way to achieve the requirement? If so, how can we test it?

 

It would be helpful if anyone could guide me on this.

1 REPLY 1

Sid_Takali
Kilo Patron

Hi @GnaneshwaraP 

Create a New Inbound Email Action:

  • Define the conditions under which this action should trigger (e.g., when an email is sent to escalations@abc.com).
  • Write below like code
(function runMailScript(email, template, incomingEmail) {
    var senderEmail = email.headers.from; 
    var gr = new GlideRecord('incident');
    if (gr.get('YOUR_INCIDENT_SYS_ID')) { // Replace with actual incident record retrieval condition
        gr.sender_mail = senderEmail; 
        gr.update();
    }
})(email, template, incomingEmail);

https://www.servicenow.com/community/incident-management-forum/how-to-get-the-sender-email-address-f...

https://www.servicenow.com/community/developer-forum/inbound-email-action-populate-user-as-requester... 

 

Regards,

Sid