How to block “Re:” email threads from creating new tickets in ServiceNow?

mania
Tera Contributor

Hi,

How to block “Re:” email threads from creating new tickets in ServiceNow?

When a reply email (with “Re:” in the subject) is received, it should only update the existing record.
If no matching record is found, it should not create a new ticket.

Can anyone please help on this, it will be helpful.

Thanks!

1 REPLY 1

Aditya40
Tera Contributor

Hi @mania ,

 

By default, ServiceNow can create a new record when an inbound email is received, even if the subject contains “Re:” and no matching record is found. To prevent this behavior, you should control the logic in an Inbound Email Action so that reply emails only update existing records and do not create new tickets when no match exists.

 

(function runMailScript(current, template, email, email_action, event) {
    // Check if subject starts with "Re:"
    var subject = email.subject || '';
    if (subject.toLowerCase().indexOf('re:') === 0) {
        // Extract original subject (remove "Re: " prefix)
        var originalSubject = subject.replace(/^re:\s*/i, '').trim();
        // Query for existing incident by original subject in short_description
        var existing = new GlideRecord('incident');
        existing.addQuery('short_description', originalSubject);
        existing.addActiveQuery();  // Only active incidents
        existing.query();
        if (existing.next()) {
            // FOUND MATCH - Update existing incident instead
            existing.work_notes = 'Email reply received: ' + email.body_text;
            existing.update();      
            gs.log('Re: email matched existing INC ' + existing.number + 
                   ' (Subject: ' + originalSubject + ')');       
            return;  // Exit - NO new ticket created
        }
    }
    // NO MATCH or not a "Re:" email - Create new incident
    current.short_description = email.subject;
    current.description = email.body_text;
    current.caller_id = email.from;
    current.insert();
})(current, template, email, email_action, event);

How it works

  • Detects "Re:" emails using subject.toLowerCase().indexOf('re:') === 0
  • Strips "Re:" prefix to get original subject: "Re: Server down" → "Server down"
  • Searches active incidents by matching short_description
  • If match found: Updates work_notes → NO new ticket
  • If no match: Creates new incident normally

If this answer has addressed your question, please mark it as the accepted solution and give it a thumbs up.
Thank You.