- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
47m ago
Hi,
I want to copy an attachment, but how do I do that?
Is it possible to do this using GlideSysAttachment?
If not, another method is fine.
Copy source:Files attached to the file attachment type column of the abccabc table in the abc application scope
Copy destination:Record of the efgefg table in the abc application scope
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
23m ago
Your traditional GlideSysAttachment.copy() won't work here i.e. record to record
you need to tweak the logic since you want to copy from Attachment type Field to target record
Example: you can use this server side code in business rule on abc table on record insert and it will add that file to other table record
Note: you need to enhance it further
I did it in background script and it should work in scoped app as well
var targetRecord = new GlideRecord("change_request");
targetRecord.addQuery("sys_id", "6ae8a3272b0366d04a2bfbfdf291bf12");
targetRecord.query();
if (targetRecord.next()) {
var sourceRecord = new GlideRecord('incident');
if (sourceRecord.get('00c01445fb5532500db5f8454eefdcc9')) {
new global.VariableUtil().copyAttachment(sourceRecord.u_my_file, 'change_request', targetRecord.sys_id);
}
}
Output:
💡 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
43m ago
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
32m ago
Thank you for your reply.
When I tried to copy using the logic below, when I looked at the sys_attachment table, the destination table name had ZZ_YY attached to it.
I would like to copy the data without the ZZ_YY attached to the destination table.
-------------------------------------------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
23m ago
Your traditional GlideSysAttachment.copy() won't work here i.e. record to record
you need to tweak the logic since you want to copy from Attachment type Field to target record
Example: you can use this server side code in business rule on abc table on record insert and it will add that file to other table record
Note: you need to enhance it further
I did it in background script and it should work in scoped app as well
var targetRecord = new GlideRecord("change_request");
targetRecord.addQuery("sys_id", "6ae8a3272b0366d04a2bfbfdf291bf12");
targetRecord.query();
if (targetRecord.next()) {
var sourceRecord = new GlideRecord('incident');
if (sourceRecord.get('00c01445fb5532500db5f8454eefdcc9')) {
new global.VariableUtil().copyAttachment(sourceRecord.u_my_file, 'change_request', targetRecord.sys_id);
}
}
Output:
💡 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
