How to add the received email's attachment to the incident via inbound action

VIKAS MISHRA
Tera Contributor

we have already build one inbound action so that we can get our incident creation and updation automatically via received emails from a particular email address. however the 3rd party also sending us the attachment attached with that email, now we need to know how can we add that received attachment to our incident. please suggest. 

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @VIKAS MISHRA 

 

1. Do you want to update the existing record or new record?

2. To do this, you need to add some kind of identifier like Subject contains 3rd Party or Attachment name xxxxxx.sss or of you have only 1 3rd party then mention specific email to trigger this inbound action. (I had same use case earlier)

 

https://www.servicenow.com/community/service-management-forum/attach-incoming-email-to-incident/m-p/...

 

https://www.servicenow.com/community/service-management-forum/need-to-attach-attachment-to-the-incid...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

as per the thread you provided above its OOB functionality that attachment should add to the incident if its a reply email, 

 

my emails are also reply email but it's not getting attached to the incident, is it beacuse something is wrong in the script in our inbound action. 

 

Below is the inbound action script.

 

(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

    // Implement email action here
    var an = email.body_text;
    var at_inc = email.body.autotask_inc_number;
    var wn = email.body.autotask_ticket_description;
    var rn = email.body.autotask_resolution;
    //var sn = email.body.autotask_ticket_status;
    var tn = email.body.autotask_ticket_title;
	
var startStr = an.indexOf("autotask_ticket_status:");
 var endStr = an.indexOf("autotask_resolution:");
 var statusVal = an.slice(24, endStr);
 var sn = statusVal.trim();
	
    gs.log('at178: numbers' + at_inc);
    gs.log('at178: autotask_ticket_description' + wn);
    gs.log('at178: autotask_ticket_status' + sn.trim());

    var numberPattern = "/INC\[0-9]{7}/"; //Looking for IN plus 0-9 numbers, six number in  total
    var reg = new SNC.Regex(numberPattern);
    var matchedNumber = reg.match(email.subject);
    gs.log('at1: match' + matchedNumber);
    if (JSUtil.notNil(matchedNumber)) { //matchedNumber will be NULL if a match is not found in the email subject.   If NULL we know this is a new email
        var inc_rec = new GlideRecord('incident');
        inc_rec.addQuery('number', matchedNumber);
        //inc_rec.addQuery('number', inc);

        inc_rec.query();
        if (inc_rec.next()) {

            if (sn.trim() == "Assigned To Coforge") {
               // var parser = /autotask_resolution:([\s\S]*)autotask_inc_number:/m;
                //var ans = parser.exec(an);
                   //gs.log('ans' + ans);
                // gs.log('ans0' + ans[0]);
                //gs.log('ans1' + ans[1]);
                //                 var parser = '/autotask_resolution:([\s\S]*)autotask_inc_number:/m';
                //                 var ans = parser.exec(an);
                //                 gs.log('ans' + ans);
                //                 // gs.log('ans0' + ans[0]);
                //                 gs.log('ans1' + ans[1]);

                gs.log('at198 : Assigned to Coforge');
                inc_rec.assignment_group = '7c77b2e71b0c4d10680a0e9cdc4bcb4e'; //GSD Group
                inc_rec.update();
                var description1 = [];
                // description1.push("Title " + '-' + tn);
               // description1.push("Resolution Notes " + '-' + ans[1]);
				description1.push("Resolution Notes " + '-' + rn);
                description1.push("Autotask Ticket Status  " + '-' + sn);


                var results1 = description1.join("\n");


                inc_rec.work_notes = results1;
                //inc_rec.work_notes =  'Title - ' + tn + "\n" + 'Description - ' + wn + "\n" + 'Autotask Ticket status - ' + sn;
                inc_rec.update();

            } else if (sn.trim() == "Complete") {
               // var parser = /autotask_resolution:([\s\S]*)autotask_inc_number:/m;
                //var ans = parser.exec(an);
                //gs.log('ans' + ans);
                      // gs.log('ans0' + ans[0]);
                //gs.log('ans1' + ans[1]);
                //gs.log('at178: inc' + matchedNumber);
                //inc_rec.close_notes = ans[1];
				inc_rec.close_notes = rn;
                inc_rec.close_code = 'Closed/Resolved by Caller';
                inc_rec.state = '6';
                inc_rec.update();

                //inc_rec.work_notes = 'Title - ' + tn;
                var description = [];
                //  description.push("Title " + '-' + tn);
                //description.push("Close Notes " + '-' + ans[1]);
				description.push("Close Notes " + '-' + rn);
                description.push("Autotask Ticket Status  " + '-' + sn);


                var results = description.join("\n");


                inc_rec.work_notes = results;
                //inc_rec.work_notes =  'Title - ' + tn + "\n" + 'Description - ' + wn + "\n" + 'Autotask Ticket status - ' + sn;
                inc_rec.update();
            }
            // (sn.trim() != ('Complete' && 'Assigned To Coforge')) {
            else {
                var parser = /autotask_ticket_description:([\s\S]*)autotask_inc_number:/m;
                var ans = parser.exec(an);
                gs.log('ans' + ans);
                // gs.log('ans0' + ans[0]);
                gs.log('ans1' + ans[1]);

                var description2 = [];
                description2.push("Title " + '-' + tn);
                description2.push("Description " + '-' + ans[1]);
                description2.push("Autotask Ticket Status  " + '-' + sn);


                var results2 = description2.join("\n");


                inc_rec.work_notes = results2;
                //inc_rec.work_notes =  'Title - ' + tn + "\n" + 'Description - ' + wn + "\n" + 'Autotask Ticket status - ' + sn;
                inc_rec.update();
            }
        }
        // 		if((inc_rec.next()) && (sn == 'completed')){
        // 			inc_rec.state = '6';
        // 			
        // 			inc_rec.update();
        // 		}
    }


})(current, event, email, logger, classifier);

 

HI @VIKAS MISHRA 

 

Sorry mate, i am not coder who can help you on coding :(.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

If the replies to an Incident Notification are not getting attached you might have some problems.

Some questions:

Are they removing the reference tag?  The system will use this to determine what rule needs to run.

Are external users replying, is your instance set to ignore these senders?