How to update an existing incident using inbound email action if existing incident mentioned in subj

Naresh_5120
Tera Contributor

Dear community,

 

I am looking for solution to update the existing incident (work notes) using inbound email action if an existing incident mentioned in subject line of an email (It could be New, reply or forward email )

 

Regards,
Naresh

6 REPLIES 6

Dipen Wadhwana
Giga Guru

Hi @Naresh_5120 ,

 

Create a script to parse incoming email subject, extract incident number, query Incident table in ServiceNow, and update corresponding incident record with information from email body.

// Parse email subject to extract incident number
var incidentNumber = email.subject.match(/\bINC\d+\b/)[0]; 

// Query Incident table to find the incident record
var grIncident = new GlideRecord('incident');
if (grIncident.get('number', incidentNumber)) {
    // Update the incident record
    grIncident.short_description = email.body_text; // Update with email body content
    grIncident.update();
}

Please mark this response as helpful if your question has been answered

Dear @Dipen Wadhwana ,

 

Thank you so much for this script its working perfectly fine, but i have one challenge is, besides  updating existing incident record, it is also creating new incident. How can I modify the existing inbound action (to create new incident) to see that if incident is already exist in ServiceNow , it should not create a incident just update the existing incident.