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

Raghu3
Tera Contributor

Use event.state="stop_processing after gr.update(). also use else if and check incident number.

Also check if any other inbound action is not creating the new incident

@Raghu3  Thanks for your response.

Logs are showing the same inbound action creating a new record. 

I tried the event.state="stop_processing after gr.update() but no success. 

 

maroon_byte
Mega Sage

Select 'Stop Processing' checkbox. You may have another incident creation inbound action (out of the box one may be) that is triggered after your inbound action is processed.

 

Execution order is also important. If the other inbound action does not have 'Stop Processing' checked and is of lower execution order than your inbound action, then a new incident is created before an existing incident is updated.

Thanks @maroon_byte I have tried the checkbox and the logic in the script to stop processing but the instance is still being generated and also made sure this action runs before any other actions 

GB14
Kilo Patron

@Ankur Bawiskar Any suggestions in this case? Thanks