Requirement to attach the mail to the incident in email integration

Kayathri
Tera Contributor

Hi Team,

 

Having the requirement, when the incident is triggered with email integration, want to attach the same mail which triggered the incident to the incident form. Kindly guide.

 

Regards,

Kayathri

2 REPLIES 2

Riya Verma
Kilo Sage
Kilo Sage

Hi @Kayathri ,

 

Hope you are doing great.

 

  1. Set up email integration in ServiceNow so that incoming emails can be captured and processed as incidents. This can be done through the Email Inbound Action module.

  2. , create a Business Rule that will run when a new incident is created. This rule will handle the email attachment and ensure it i attached to the incident form.

  3. In the Business Rule, use GlideEmailInbound to access the email content and attachments. Extract the email attachment and store it as an attachment on the newly created incident record.

 

(function executeRule(current, previous) {
    var emailInbound = new GlideEmailInbound(current);
    var emailAttachment = emailInbound.getAttachmentStream('attachment_name'); // Replace 'attachment_name' with the actual name of the attachment.

    if (emailAttachment) {
        var grAttachment = new GlideSysAttachment();
        grAttachment.write(current, 'attachment_name', emailAttachment, 'text/plain'); // Replace 'attachment_name' with the desired attachment name and 'text/plain' with the appropriate MIME type if needed.
    }
})(current, previous);

 

 
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma

Hi Riya,

 

Thanks for the reply, I don't have the attachment name, the attachment is the mail that triggers the incident using email integration (The same mail that hits the instance, incident will be created, that mail to be attached to the incident), so the mail changes every time. Please suggest me.

 

Regards,

Kayathri