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

Inbound Action attachment

mohanambalnanja
Tera Contributor

Hi All,

 

I am trying to add attachment in Inbound action. 

When the emails comes first, it creating an incident and adding an attachment from the email.

We have a condition, if there is an existing ticket for the same email, then we just need to update email body in the work notes and add attachment in the existing incident.

 

As per the below code its checking for the existing ticket, if it is found updating work notes with the email body. 

 

Please let me know if there is any out of the box function to add the attachment in existing ticket .

 

If not, I need to glide Attachment table and update the table sys ID and table name as per my condition. 

 

 var mailBody = email.body_text.toString();
 var checkINC = new GlideRecord('incident');

 checkINC.addEncodedQuery('incident_stateNOT IN6,7');
 checkINC.addQuery('u_deduplication_key',email.subject);
 checkINC.query();

 if (checkINC.next())
 {
     // Existing ticket found, update it
     checkINC.work_notes = mailBody;
     checkINC.update();
 }
 
Thanks in advance.
1 ACCEPTED SOLUTION

Voona Rohila
Mega Patron
Mega Patron

Hi @mohanambalnanja 

You can use GlideSysAttachment Copy method.

Refer GlideSysAttachment Copy

 var mailBody = email.body_text.toString();
    var checkINC = new GlideRecord('incident');

    checkINC.addEncodedQuery('incident_stateNOT IN6,7');
    checkINC.addQuery('u_deduplication_key', email.subject);
    checkINC.query();

    if (checkINC.next()) {
        // Existing ticket found, update it
        new GlideSysAttachment().copy('sys_email', sys_email.sys_id, 'incident', checkINC.sys_id);
        checkINC.work_notes = mailBody;
        checkINC.update();

    }

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

2 REPLIES 2

Voona Rohila
Mega Patron
Mega Patron

Hi @mohanambalnanja 

You can use GlideSysAttachment Copy method.

Refer GlideSysAttachment Copy

 var mailBody = email.body_text.toString();
    var checkINC = new GlideRecord('incident');

    checkINC.addEncodedQuery('incident_stateNOT IN6,7');
    checkINC.addQuery('u_deduplication_key', email.subject);
    checkINC.query();

    if (checkINC.next()) {
        // Existing ticket found, update it
        new GlideSysAttachment().copy('sys_email', sys_email.sys_id, 'incident', checkINC.sys_id);
        checkINC.work_notes = mailBody;
        checkINC.update();

    }

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

mohanambalnanja
Tera Contributor

@Voona Rohila ,

 

Thank you very much. It worked.