Copy attachment added via service catalog variable

michelhanna
Kilo Guru

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,

1 ACCEPTED SOLUTION

michelhanna
Kilo Guru

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:

  1. Rename the table name field to remove the ZZ_YY
  2. Use this alternative copy: new global.VariableUtil().(attachmentId, targetTable, targetId); which does NOT add ZZ_YY.

View solution in original post

13 REPLIES 13

Mike Patel
Tera Sage

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);

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".

michelhanna
Kilo Guru

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:

  1. Rename the table name field to remove the ZZ_YY
  2. Use this alternative copy: new global.VariableUtil().(attachmentId, targetTable, targetId); which does NOT add ZZ_YY.

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader