
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2024 08:27 AM - edited 11-12-2024 08:29 AM
Hi, i know that an email that is classed as a new email is for just that, but i need the script to check to see if a ServiceNow number is contained and if so, to update the existing ticket rather than creating a new ticket.
The inbound action i created is flagged to stop processing after it runs and I can see that in the email log. However, I have added log statements in the script and none of them appear to get triggered.
The script I have so far is as follows and any help would be greatly appreciated:
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*EmailAction*/ email_action, /*GlideRecord*/ email_log, /*EmailClassifier*/ classifier) {
// Extract the SN ID from the email body
var emailBody = email.body_text;
var snID = extractID(emailBody); // Implement this function to extract the SN ID
if (snID) {
var gr = new GlideRecord('sn_si_request');
gr.addQuery('number', snID);
gr.query();
if (gr.next()) {
// Update the existing record
gr.work_notes = emailBody;
gr.update();
gs.log('MiA Record updated for SN ID: ' + snID);
} else {
// Create a new record if no match is found
current.short_description = email.subject;
current.description = emailBody;
current.insert();
gs.log('MiA New record created for SN ID: ' + snID);
}
} else {
gs.log('MiA No SN ID found in the email body.');
}
function extractID(body) {
// Implement your logic to extract the SN ID from the email body
var snIDPattern = /ServiceNow ID:\s*\[(\d+)\]/; // Example pattern, adjust as needed
var match = body.match(snIDPattern);
return match ? match[1] : null;
}
})(current, event, email, email_action, email_log, classifier);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 05:42 AM
I achieved what I wanted by getting the sender to prefix the subject with Re: in order to trick it into thinking it was a reply!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2024 05:42 AM
I achieved what I wanted by getting the sender to prefix the subject with Re: in order to trick it into thinking it was a reply!