- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 12:35 PM
Hello,
A user replies to an existing sctask email notification with an attachment. The inbound email is added email body text to the correct record, but the attachments are not getting attach. Below is the script I'm currently using. Could someone please provide suggestion on how to get it to works. Thank you
// Extract the SCTASK number from the email subject
var taskNumber = email.subject.match(/SCTASK\d+/);
if (taskNumber) {
// Query the Task table for the matching SCTASK record
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('number', taskNumber[0]);
taskGR.query();
if (taskGR.next()) {
// Add email body to the Work Notes or Comments
// taskGR.comments = email.body_text;
taskGR.work_notes = email.body_text;
// Attach files from the email to the SCTASK
var attachment = new GlideSysAttachment();
attachment.copy('sys_email', email.sys_id, 'sc_task', taskGR.sys_id);
// Update the SCTASK record
taskGR.update();
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-26-2024 06:39 PM - edited 12-26-2024 06:50 PM
are you saying user had attached some file such as word, pdf etc and it's not getting attached?
your code should attach it to target record
update as this, attachment copy should be after the update without which you won't get sysId of record
// Extract the SCTASK number from the email subject
var taskNumber = email.subject.match(/SCTASK\d+/);
if (taskNumber) {
// Query the Task table for the matching SCTASK record
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('number', taskNumber[0]);
taskGR.query();
if (taskGR.next()) {
// Add email body to the Work Notes or Comments
// taskGR.comments = email.body_text;
taskGR.work_notes = email.body_text;
// Attach files from the email to the SCTASK
var attachment = new GlideSysAttachment();
// Update the SCTASK record
taskGR.update();
attachment.copy('sys_email', sys_email.sys_id, 'sc_task', taskGR.sys_id);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 08:34 AM
Good morning @Omkar Mone ,
Thank you for your assistance. I was able to retrieve the email response along with the attached file, and it has been linked to the existing SCTASK record correctly.
However, the issue I'm encountering is that when I save the Outlook email and attach it, the file extension changes from ".msg" to ".eml," as shown in the images below. Is there a way to prevent this from happening?. It is working fine with other file format such as word, pdf etc..., but not .msg
For example: I saved outlook emal file as .msg
It shows in ServiceNow as message.eml. Even the file name got changed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-27-2024 05:48 PM
This typically happens because ServiceNow's email processing system is designed to handle .eml files more effectively.
within ServiceNow it's handled with extension .eml
.msg extension is only for microsoft outlook
We cannot do much with this.
I hope I have provided a thorough answer to your question. I'm confident that with your developer skills, you can take it further from here.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader