Email link to case with case number from the subject
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 05:27 AM
Hello everyone
We have a special case where a ticket system sends tickets to us by e-mail and receives a reply. If an e-mail is sent from the ticket system to ServiceNow, the Ref_ID cannot be included in the body.
We have created an e-mail inbound action that extracts the case number contained in the subject and then attaches the e-mail to the recognized ticket.
If we want to write a comment, this is generated, as is a work note. Only the e-mail is not attached to the case.
here our inbound action script:
(function runAction( /*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {
var subject = email.subject || '';
var match = subject.match(/CS\d{7}/); // Searches for e.g. "CS1234567"
if (!match) return;
var caseNumber = match[0];
gs.info("msg inbound email CS in Subject Case Number: " + caseNumber);
// Load the case using the number
var caseGR = new GlideRecord('sn_customerservice_case');
caseGR.addQuery('number', caseNumber);
caseGR.query();
if (!caseGR.next()) return; // Case not found
// Load the sender as Customer Contact
var contactGR = new GlideRecord('customer_contact');
contactGR.addQuery('email', email.origemail);
contactGR.query();
var validContactFound = false;
while (contactGR.next()) {
if (contactGR.account == caseGR.account) {
validContactFound = true;
gs.info("msg inbound email CS in Subject Account: " + caseGR.account.name + "Contact: " + contactGR.name);
//break;
}
}
if (!validContactFound) return; // No valid contact found for the company of the case
gs.info("msg inbound email CS in Subject: no return");
sys_email.target_table = "sn_customerservice_case";
sys_email.instance = caseGR.getUniqueValue();
caseGR.needs_attention =true;
caseGR.update();
})(current, event, email, logger, classifier);
I have understood it so far that
sys_email.target_table = "sn_customerservice_case"; sys_email.instance = caseGR.getUniqueValue();
attaches the e-mail to the case and also appears in the related list of e-mails.
Thank you very much for your help.
Kind Regards
Andreas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2025 10:37 AM - edited 07-09-2025 10:38 AM
Hi @AndreasRitter
Did you try this?
this will attach email to case record and attachment will also reflect in activity.
If you want to write whole email in activity, then try this
email.setTarget(caseGR);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2025 12:03 AM
Thank you for your answers, unfortunately it is still not working.
We have now decided to implement this via the Flow Designer.