The CreatorCon Call for Content is officially open! Get started here.

add attachments to the table through email

shivaadapa
Tera Expert

Hi 

How to attach any files to the incident record through inbound email action.
In the instance there is a OOTB create incident inbound email action but there is no any attachment related code over there.

5 REPLIES 5

Maddysunil
Kilo Sage

@shivaadapa 

  1. You'll need to modify the script to handle attachments. Here's a basic outline of what you'll need to do:

    • Parse the email message to extract attachments.
    • Create records in the appropriate attachment table (such as sys_attachment).
    • Associate the attachments with the newly created incident record.
  2. Example Code: Below is a simplified example of how you might modify the script to handle attachments. This example assumes that the attachments are included as part of the email body

 

// Extract attachments from email
var attachments = email.getAttachments();

// Iterate over attachments
for (var i = 0; i < attachments.size(); i++) {
    var attachment = attachments.get(i);
    
    // Create attachment record
    var attachmentRecord = new GlideRecord('sys_attachment');
    attachmentRecord.initialize();
    attachmentRecord.table_name = 'incident';
    attachmentRecord.file_name = attachment.getName();
    attachmentRecord.content_type = attachment.getContentType();
    attachmentRecord.file_size = attachment.getSize();
    attachmentRecord.sys_created_by = gs.getUserID(); // Set the creator as needed
    attachmentRecord.insert();

    // Associate attachment with incident record
    var incidentAttachment = new GlideSysAttachment();
    incidentAttachment.write(incidentSysID, attachmentRecord.getUniqueValue());
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks