- 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,415 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
10-21-2021 12:58 PM
This is what seems working:
var attachment = new global.GlideQuery('sys_attachment')
.where('table_sys_id', current.sys_id)
.where('file_name', current.<field_name>.getDisplayValue())
.selectOne('table_sys_id')
.get();
new global.VariableUtil().copyAttachment(attachment.sys_id, 'sys_data_source', dataSourceID);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 02:56 AM
This code does not work on my side (tested in a background script - with relevant values-, in "run script" of the workflow - with relevant references-... This issue is actually refering to the syntax, a function name is expected.
new global.VariableUtil().(attachmentId, targetTable, targetId);
XML runtime not available
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2022 03:05 AM
The right function call is :
new global.VariableUtil().copyAttachment(attachmentId, targetTable, targetId);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 12:46 PM
where do I provide this code? in a BR on the target table or in the record producer script?