How to distinguish between attachments types when copying them over?

Johannes Mweli
Giga Guru

Hi ServiceNow Community Developers,

Is there a way to prevent the File Attachment (ZZ_YY) attachment types from being copied over when copying attachments from one record to another using this method - GlideSysAttachment.copy('change_request', mySysID, 'change_request', sysID);

For instance, we have a UI Action that creates a new change request out of the existing change request and we copy some fields from the existing change to the new one during creation. We also copy attachments from existing one to the new one, however we don’t want to copy all attachments during the change creation. We would like to copy only the attachments that appear at the top of the form and not the ones that you upload on the form when you have a field type of File Attachment on the form. Is there a way then to actually copy only the ones at the top of the form but leave out the ones whose field type is “File Attachment” which are the ones that get stored with a ZZ_YY table prefix on the sys_attachment table?

Kindly advise please.

Thanks,

Johannes

1 ACCEPTED SOLUTION

Johannes Mweli
Giga Guru

Hi ServiceNow Community Developers,

 

By the way I figured out the solution to the question I asked above. It is thoroughly documented here https://snprotips.com/blog/2016/2/25/understanding-and-using-glideattachment 

The script is very straightforward - you can just copy and paste it into your function and you are good to go. I recommend reading the entire documentation to make sure you fully understand how attachments are stored in ServiceNow but the solution to my problem starts from the "Copying/Moving an Attachment" section in the provided link.

View solution in original post

2 REPLIES 2

Mohith Devatte
Tera Sage
Tera Sage

hello @Johannes Mweli ,

before copying you can check this condition like below 

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id',current.sys_id);
gr.addEncodedQuery('table_nameNOT LIKEzz_yy');
gr.query();
if(gr.next())
{
GlideSysAttachment.copy('change_request', mySysID, 'change_request', sysID);
}

Hope this helps 

Mark my answer correct if this helps you

 

Johannes Mweli
Giga Guru

Hi ServiceNow Community Developers,

 

By the way I figured out the solution to the question I asked above. It is thoroughly documented here https://snprotips.com/blog/2016/2/25/understanding-and-using-glideattachment 

The script is very straightforward - you can just copy and paste it into your function and you are good to go. I recommend reading the entire documentation to make sure you fully understand how attachments are stored in ServiceNow but the solution to my problem starts from the "Copying/Moving an Attachment" section in the provided link.