- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 12:56 AM
Hi,
I have a requirement to match unique number in email subject (Not ServiceNow record or water mark) and create a new ticket if match is not found in active tickets list or update ticket if match is found.
I have started matching complete subject line with the help of other community post.It but I still could not get the unique no in subject at all. Unfortunately we are unable to match with complete subject line.
Any help would be really appreciated
Example:
- Unique reference start with (00DU0JKNe_)
This scrip is match with complete subject. but i only want to match unique no in subject line.
//Check for Current Open Incident and Update
var eSubject = email.subject;
var grInc = new GlideRecord('incident');
var grEmail = new GlideRecord('sys_email');
var incUpdated = false;
//Weeks ago
//grEmail.addEncodedQuery('sys_created_onONThisweek@javascript:gs.beginningOfThisWeek()@javascript:gs.endOfThisWeek()^subject=' + eSubject);
//Find the matching subject
grEmail.addEncodedQuery('^subject=' + eSubject);
grEmail.query();
if(grEmail.getRowCount != 0){
while(grEmail.next() && incUpdated != true){
grInc.get(grEmail.instance);
if(grInc.active == true){
incUpdated = true;
grInc.work_notes = '\nFrom: ' + email.from + '\nTo: ' + email.to + '\nSubject: ' + email.subject + '\n\n' + email.body_text;
sys_email.target_table = "incident";
sys_email.instance = grInc.sys_id;
sys_email.update();
grInc.update();
gs.log("update:Existing ticket updated through:" + grInc.number, "EMAIL." + sys_email.sys_id);
}
}
}
if(incUpdated == false){
// If existing incident not found create new incident
current.caller_id = gs.getUserID();
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
current.work_notes = "received from: " + email.origemail + "\n\n" + email.body_text;
current.type = "Request";
current.incident_state = IncidentState.NEW;
current.notify = 2;
current.contact_type = "email";
if (email.body.assign != undefined)
current.assigned_to = email.body.assign;
if (email.importance != undefined) {
if (email.importance.toLowerCase() == "high") {
current.impact = 1;
current.urgency = 1;
}
}
current.insert();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2020 03:37 AM
So I think you want to check the number is in the subject of any email? And then update the incident record for those emails. If no match found then insert?
Can you try like this:
//Check for Current Open Incident and Update
var eSubject = email.subject;
var regex = /00DU0JKNe_(\d*)/g;
eSubject = eSubject.match(regex);
var grInc = new GlideRecord('incident');
var grEmail = new GlideRecord('sys_email');
var incUpdated = false;
//Find the matching subject
grEmail.addQuery('subject', 'CONTAINS', eSubject);
grEmail.query();
while (grEmail.next() && incUpdated != true && eSubject) {
grInc.get(grEmail.instance);
if (grInc.active == true) {
incUpdated = true;
grInc.work_notes = '\nFrom: ' + email.from + '\nTo: ' + email.to + '\nSubject: ' + email.subject + '\n\n' + email.body_text;
sys_email.target_table = "incident";
sys_email.instance = grInc.sys_id;
sys_email.update();
grInc.update();
gs.log("update:Existing ticket updated through:" + grInc.number, "EMAIL." + sys_email.sys_id);
}
}
if (incUpdated == false) {
// If existing incident not found create new incident
current.caller_id = gs.getUserID();
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
current.short_description = email.subject;
current.work_notes = "received from: " + email.origemail + "\n\n" + email.body_text;
current.type = "Request";
current.incident_state = IncidentState.NEW;
current.notify = 2;
current.contact_type = "email";
if (email.body.assign != undefined)
current.assigned_to = email.body.assign;
if (email.importance != undefined) {
if (email.importance.toLowerCase() == "high") {
current.impact = 1;
current.urgency = 1;
}
}
current.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-03-2020 02:28 PM
Hello, I think I am trying to do exactly the same thing. If the subject line of an email has a number in it, I want to create an incident. Then if I receive another email with a slightly different subject line but the same number in it, I want to UPDATE the existing incident with an inbound action. I have tried all the scripts in this post but none are working for me. Denu, did you ever figure this out? Any help would be appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-07-2020 07:16 PM
Hi Diane,
This script works for me, only thing is when ticket update through these inbound action it doe not show up in the Email logs, but record create and update works without any issue.
Please try attached update set in your personal developer instance.
Also make sure to check your system property values as well/
glide.email.reply_subject_prefix
re:,aw:,r:,Accepted:,Tentative:,Declined:,Case:
glide.email.forward_subject_prefix
fw:,fwd:,FW:,Fw: