Inbound action issue

GB14
Kilo Patron

I am working on an inbound action where we have to capture the vendor's response and action accordingly. 

1) If the email subject does not contain our INC####### - Create a new incident 

2) If the email subject contains our INC####### - Then update it and do not create a new incident. 

 

With the following script, an Incident is found and comments are added but at the same time, a new incident is getting created. Any suggestions or assistance with this issue will be appreciated. 

 

Inbound action: 

GB14_0-1694197706526.png

 

Script: 

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

    gs.include('validators');
    if (current.getTableName() == "incident") {

        //This gets you the INC number similar code can be used to get the ref number in your case.
        var index = email.subject.indexOf("INC");
        var incNumber = email.subject.substring(index, index + 10);
        gs.log(incNumber, 'testFound');
        var gr = new GlideRecord('incident');
        gr.addQuery('number', incNumber);
        gr.query();
        if (gr.next()) {
            gr.work_notes = "reply from: " + email.origemail + "\n\n" + email.body_text;
            gr.update();

        } else {
            // If existing incident not found create new incident
			gs.log(incNumber, 'testCreated');

            current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
            current.short_description = email.subject;
            current.work_notes = "received from (create action): " + email.origemail + "\n\n" + email.body_text;
            current.state = "1";
            current.caller_id = "1656acec870575508a267556cebb353c";
            current.contact_type = "email";

            //var emailPriority = email.body_text.indexOf("Priority: ");


            //Low
            if (email.body_text.indexOf("Priority: Low") > 0) {
                current.impact = 3;
                current.urgency = 2;
            }

            //Medium
            else if (email.body_text.indexOf("Priority: Medium") > 0) {
                current.impact = 2;
                current.urgency = 2;
            }

            //High
            else if (email.body_text.indexOf("Priority: High") > 0) {
                current.impact = 2;
                current.urgency = 1;
            }
            //Urgent
            else if (email.body_text.indexOf("Priority: Urgent") > 0) {
                current.impact = 1;
                current.urgency = 1;
            }


            current.insert();

        }

    }
    event.state = "stop_processing";

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

 

Thanks in advance 

9 REPLIES 9

jonsan09
Giga Sage
Giga Sage

You could try changing line 17 from an else statment to an else if statment to ensure the incNumber value is empty

        } else if (!incNumber) {

@jonsan09 Thanks for your response! 
I tried updating the script but had no success. A

n inbound email Created a new incident and also updated the incident # listed in the subject line. 

Try changing it to just a a seperate if statement 

if (!incNumber)

@jonsan09  -  same results, inbound email updated the incident and also created a new incident.