- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2025 08:15 AM
Hi,
I am trying the copy attachment from sys_email to case record so i havee used below code but not getting mapped.
Can anyone please let us know where i missed?
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2025 08:51 AM
Is the email coming of type Reply and it has attachment and you want to add that file to target record?
If yes then do this in inbound action of type Reply
GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'sn_customerservice_case', current.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
07-28-2025 08:13 PM
Glad to know.
Please mark my below response as correct and close the thread.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2025 08:52 AM
Hi @mania
I could see some issues in your code
- newGlideRecord is not valid – it should be new GlideRecord(...)
- Function declaration functioncopyAttachmentToTask is missing a space
- You’re calling grTask inside the function copyAttachmentToTask, but grTask is not available in its scope
- You’re using current.sys_id in sys_attachment.query() – this may refer to the sys_id of sys_email, not the attachment
- Your get(inc.instance) assumes instance refers to the case ID – that depends on your email configuration and may not be correct
May you try this one
(function executeRule(current, previous /*null when async*/) {
// Get the email record
var email = new GlideRecord("sys_email");
if (!email.get(current.sys_id)) {
return;
}
// Get the target Case record (assuming 'instance' field contains reference to sn_customerservice_case)
var caseGr = new GlideRecord("sn_customerservice_case");
if (!caseGr.get(email.instance)) {
return;
}
// Copy all attachments from sys_email to the case record
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_sys_id', email.sys_id);
attachmentGR.addQuery('table_name', 'sys_email');
attachmentGR.query();
while (attachmentGR.next()) {
var gsa = new GlideSysAttachment();
var contentStream = gsa.getContentStream(attachmentGR.sys_id);
gsa.writeContentStream(
caseGr, // Destination record
attachmentGR.file_name,
attachmentGR.content_type,
contentStream
);
}
})(current, previous);
- This script runs from a Business Rule or Email Inbound Action on the sys_email table.
- The instance field of the sys_email record contains the sys_id of the target sn_customerservice_case record.
- You want to copy all attachments from the email to the case.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2025 09:10 AM
Thanks for the reply!
I tried with your code but still not getting mapped.
Please help on this
Thanks!
