- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 06:56 PM
Hi,
I'm trying to copy an attachment file from a service catalog attachment variable.
Once the request is submitted, looking at the sys_attachment table, I see the attachment record is added but the table name is ZZ_YYsc_req_item rather than sc_req_item!
I tried both of the below to copy the file with no luck
// try ZZ_YYsc_req_item
GlideSysAttachment.copy('ZZ_YYsc_req_item','sourceSYSID','targetTable','targetSYSID');
//and try sc_req_item
GlideSysAttachment.copy('sc_req_item','sourceSYSID','targetTable','targetSYSID');
EDIT:The copy happens but the table name on the new attachment copy starts with ZZ_YY, even when I don't use that string.
Any ideas how can I copy the attachment variable to a record without the table name starts with ZZ_YY?
Thanks,
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- 6,411 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 08:30 PM
So, the root cause here is GlideSysAttachment.copy will always cause the new copy to have a table name starts with ZZ_YY for attachments variables, which according to this KB0868420 won't show on the record header.
Two options here to resolve this:
- Rename the table name field to remove the ZZ_YY
- Use this alternative copy: new global.VariableUtil().(attachmentId, targetTable, targetId); which does NOT add ZZ_YY.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 07:00 PM
you will need something like (make sure you have below code on sc_req_item table)
GlideSysAttachment.copy('ZZ_YYsc_req_item',current.sys_id,'sc_req_item',current.sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 07:19 PM
When I try
GlideSysAttachment.copy('ZZ_YYsc_req_item', current.sys_id, 'sc_req_item', current.sys_id);
the new copied file appears on the attachment table under ZZ_YYsc_req_item even when the target table is sc_req_item.
I don't understand what's with the "ZZ_YY".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 08:30 PM
So, the root cause here is GlideSysAttachment.copy will always cause the new copy to have a table name starts with ZZ_YY for attachments variables, which according to this KB0868420 won't show on the record header.
Two options here to resolve this:
- Rename the table name field to remove the ZZ_YY
- Use this alternative copy: new global.VariableUtil().(attachmentId, targetTable, targetId); which does NOT add ZZ_YY.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2021 09:25 PM
So the only way to pick the file from attachment variable to copy some target table is
1) Use the alternative new global.VariableUtil().(attachmentId, targetTable, targetId);
OR
2) remove the table name ZZ_YY before copying
please share the scripts for both the approaches so that it will be helpful to others as well.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader