Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

Inbound Email Action Not Triggering for Reply Emails

mania
Tera Contributor

Hi Team,

I'm working on the following requirement:

Requirement:
For both New and Reply emails, update the existing Incident by identifying "Servicenow ticket reference is INCxxxxx" from the email body and populate the Last Email To Customer (Date/Time) field with the current timestamp.

Current Behavior:

  • New emails: My custom Inbound Email Action is triggered, the Incident is identified from the email body contains "Servicenow ticket reference is INCxxxxx", and the Last Email To Customer field is updated correctly.
  • Reply emails: When a customer replies to the email, ServiceNow's out-of-the-box (OOB) email reply processing updates the Incident activity/work notes, but my custom Inbound Email Action is not executed. As a result, the activity log is updated, but the Last Email To Customer field is not populated.

Expected Behavior:
When a customer replies to an email and the email body contains "Servicenow ticket reference is INCxxxxx" anywhere in the body, the existing Incident should be identified and the Last Email To Customer field should be updated with the current timestamp.

 

Has anyone encountered this behavior? Is there a recommended approach to ensure custom logic executes for reply emails that are processed by the OOB email reply functionality?

Any suggestions would be appreciated.

 

Thank you!

1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @mania 

 

Could you please share your Inbound email action  trigger condition and script. (screen shot).

 

Note:  On your inbound email action, can you set Execution order lower value like 5 and check whether it is triggering.  ( if it is not working, just revert back execution order ) .Let me know the result.

 

 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

4 REPLIES 4

Tanushree Maiti
Tera Patron

Hi @mania 

 

Could you please share your Inbound email action  trigger condition and script. (screen shot).

 

Note:  On your inbound email action, can you set Execution order lower value like 5 and check whether it is triggering.  ( if it is not working, just revert back execution order ) .Let me know the result.

 

 

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

 @Tanushree Maiti ,

Thanks for the respond

mania_0-1785914518222.png

 

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

 

    // Process the email body extraction for the reply thread

    var b = UpdateIncident();

    gs.info("Quvia Reply Action: Returned Incident Sys ID = " + b);

 

    function UpdateIncident(){

   

        var body = email.body_html || email.body_text || "";

        var regex = /Servicenow\s+ticket\s+reference\s+is(?:\s|<[^>]*>)*(INC\d{7})/i;

        var match = body.match(regex);

 

        if (!match) {

            gs.info("Quvia Reply Action: Ticket reference tag was not found in the email body.");

            return null;

        }

 

        // match[1] extracts only the clean incident number string from the capture group

        var incidentNumber = match[1].toUpperCase();

        gs.info("Quvia Reply Action: Extracted Incident from Tag: " + incidentNumber);

 

        // Find the matching Incident in the database

        var inc = new GlideRecord("incident");

        inc.addQuery("number", incidentNumber);

        inc.query();

 

        if (inc.next()) {

            // Determine sender email safely

            var sender = (email.origemail || "").toLowerCase().trim();

 

            // Current date/time

            var now = new GlideDateTime();

 

            // Update the appropriate tracking timestamp field using safe indexOf check

            if (sender.indexOf("@exterprise.in") > -1) {

                // Internal sender

                inc.setValue("u_lastemail_to_customer", now);

                gs.info("Quvia Reply Action: Updated u_lastemail_to_customer for " + incidentNumber);

            } else {

                // External sender

                inc.setValue("u_lastemail_from_customer", now);

                gs.info("Quvia Reply Action: Updated u_lastemail_from_customer for " + incidentNumber);

            }

 

            inc.update();

            return inc.sys_id.toString();

        } else {

            gs.info("Quvia Reply Action: Incident not found in system matching tag: " + incidentNumber);

            return null;

        }

    }

   

    // Explicit target log mapping engine update loop

    if (b) {

        var q = new GlideRecord('sys_email');

        q.addQuery('uid', email.uid);

        q.query();

        if (q.next()) {

            q.target_table = 'incident';

            q.instance = b;

            q.update();

            gs.info("Quvia Reply Action: Target field successfully mapped to Incident Sys ID: " + b);

        }

    }

 

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

 

I tried with order but still not working.

 

Thanks!

 

Hi @mania 

 

Trigger condition screen shot , can not read. Please attach it as any image file and share it here.

 

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

yashkamde
Giga Sage

Hello @mania ,

 

ensure that type should be received and inspect Email Logs for applyInboundEmailActions, you'll see which actions matched and which didn't for that specific email.

 

Also I would recommend rather than ootb reply classification routing, the more reliable fix is to hook into sys_email directly with a Business Rule, since a sys_email record is created for every inbound email regardless of how it gets classified:

// Business Rule on sys_email
// When: after, Insert/Update
// Condition: current.type == 'received'

(function executeRule(current, previous) {

    var body = current.body_html || current.body_text || "";
    var regex = /Servicenow\s+ticket\s+reference\s+is(?:\s|<[^>]*>)*(INC\d{7})/i;
    var match = body.match(regex);

    if (!match) return;

    var incidentNumber = match[1].toUpperCase();

    var inc = new GlideRecord("incident");
    if (!inc.get("number", incidentNumber)) return;

    var sender = (current.getValue("from") || "").toLowerCase().trim();

    if (sender.indexOf("@exterprise.in") > -1) {
        inc.setValue("u_lastemail_to_customer", new GlideDateTime());
    } else {
        inc.setValue("u_lastemail_from_customer", new GlideDateTime());
    }
    inc.update();

})(current, previous);

 

If my response helped mark as helpful and accept the solution.