Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to include email attachment to the interaction ticket

Merza Lyn
Giga Guru

We have activated Interaction to our SN instance. However, when user send an email with attachment. Upon checking to the created interaction, there is no file in the Attachment Contextual Side Panel.

MerzaLyn_0-1761532247509.png

 

Inbound action script:

(function() {
    var gr = new GlideRecord('interaction');
    gr.initialize();
 
    // Set interaction type = Email
    gr.type = 'email';
 
    // Short Description from the email subject
    gr.short_description = email.subject ? email.subject.toString() : 'No Subject';
 
    // Default state to 'New'
    gr.state = 'new';
 
    // Look up user in sys_user table by email address
    var userGR = new GlideRecord('sys_user');
    userGR.addQuery('email', email.from);
    userGR.query();
 
    if (userGR.next()) {
        // Opened for = matched user
        gr.opened_for = userGR.sys_id;
 
        // Location = user's location
        if (userGR.location)
            gr.location = userGR.location;
    }
 
    // Build additional comments (no CC)
    var comments = [];
    comments.push("Subject: " + (email.subject || ""));
    comments.push("Body: " + (email.body_text || ""));
    comments.push("Recipient Info: " + (email.to || ""));
 
    // Save into Additional Comments (journal field)
    gr.u_additional_comments_customer_visible = comments.join("\n");
 
    // Insert the new Interaction
    gr.insert();
})();
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Merza Lyn 

so the incoming email has attachment but it's not getting attached to newly created interaction?

if yes then add this line and see

// Insert the new Interaction
gr.insert();

// copy file
new GlideSysAttachment().copy('sys_email', sys_email.sys_id, 'interaction', gr.getUniqueValue());

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Merza Lyn 

so the incoming email has attachment but it's not getting attached to newly created interaction?

if yes then add this line and see

// Insert the new Interaction
gr.insert();

// copy file
new GlideSysAttachment().copy('sys_email', sys_email.sys_id, 'interaction', gr.getUniqueValue());

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

Thanks, it worked.