Email Email to query table before insert
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 02:38 PM
I am trying to see if there is a Solution to query the INC table before it creates a INC for the uniqueFailureID which is in the field u_uniquefailureid. if they both match then it should update the work notes or make it listed as a child of the inital and not create a new INC. below is the current code that creates and populates the feild with the uniquefailureid
var emailBody = email.body_text;
var regex = /UniqueFailureID\s*=\s*.*:([a-f0-9\-]+)$/im;
var match = emailBody.match(regex);
if (match && match[1]) {
var uniqueFailureID = match[1];
current.u_uniquefailureid = uniqueFailureID;
current.update();
} else {
gs.log("UniqueFailureID not found in the email body for incident: " + current.number, "Inbound Email Action AAC_Automation");
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 04:40 PM - edited 03-12-2024 04:41 PM
Hi, I would think a simple check for a matching record, which you can then update, else if not found create a new record. There are many ways to achieve this but here's a basic option.
var gr = new GlideRecord('incident')
if(gr.get(customFieldname, customFieldvalue)) {
// an existing record so map some values
//gr.update();
} else {
//no match found so insert new record
//current.field = mapped.value;
//current.insert;
}