Add email history to a new ticket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I have a requirement to open a new ticket if the end user replies to a closed ticket.
but this new ticket needs context - it is linked to the original - but there is now a requirement to add the history of the original ticket - which is fine - until it comes to the email history - i cannot get it to copy that information across in any format
are there any suggestions or anyone that has done this before that can give me a few pointers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
ahoy @Ross Walker,
by "ticket" you mean incident? Once incident is closed then it's inactive and cannot be answered to it... or you mean by an email?
Where the rules are real, you'll find me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Sorry - Yes Ticket - i do mean incident
and yes replied to by email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hey @Ross Walker
A practical approach is:
- Create the new Incident.
- Store a reference to the original Incident (Parent Incident or a custom reference field).
- Retrieve the related email records from sys_email.
- Build a formatted email history.
- Add that history to a work note, custom field, or an attachment on the new Incident.
Example:
// Original Incident
var originalIncident = current;
// Create new Incident
var newInc = new GlideRecord('incident');
newInc.initialize();
newInc.short_description = 'Follow-up to closed Incident ' + originalIncident.number;
newInc.description = originalIncident.description;
// Optional relationship
newInc.u_original_incident = originalIncident.sys_id;
var newIncidentSysId = newInc.insert();
// Build email history
var emailHistory = '';
var emailGR = new GlideRecord('sys_email');
emailGR.addQuery('instance', originalIncident.sys_id);
emailGR.orderBy('sys_created_on');
emailGR.query();
while (emailGR.next()) {
emailHistory += '\n================================================';
emailHistory += '\nType: ' + emailGR.type;
emailHistory += '\nDate: ' + emailGR.sys_created_on;
emailHistory += '\nSubject: ' + emailGR.subject;
emailHistory += '\nFrom: ' + emailGR.user;
emailHistory += '\n------------------------------------------------';
emailHistory += '\n' + emailGR.body_text;
emailHistory += '\n';
}
// Update the new Incident
var targetInc = new GlideRecord('incident');
if (targetInc.get(newIncidentSysId)) {
targetInc.work_notes =
'Created from closed Incident ' +
originalIncident.number +
'\n\nEmail History:\n' +
emailHistory;
targetInc.update();
}
A few things to keep in mind:
- Large email threads can exceed journal field size limits.
- If the original emails are HTML, you may need to use body instead of body_text, or strip the HTML depending on how you want the history displayed.
- Email attachments are not copied automatically. If they are required, they can be duplicated using GlideSysAttachment.
- For very long conversations, I would recommend generating a text or PDF file containing the email history and attaching it to the new Incident instead of placing everything into work notes.
In many implementations, the preferred approach is to create the new Incident, relate it to the original Incident, and simply provide a reference back to the original record. This avoids duplicating large amounts of data while still giving analysts access to the complete conversation whenever needed.
************************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb