How to copy attachment from sys_attachment table to a field

Sarika S Nair1
Kilo Sage

How to copy attachment from sys_attachment table to a field of file attachment type in a custom table.

1 ACCEPTED SOLUTION

Hi,

then the same script can be used to update the attachment field

var att = new GlideRecord('sys_attachment');

att.addQuery('table_sys_id', current.sys_id);

att.query();

if(att.next()){

current.attachment_fieldName = att.sys_id;
current.setWorkflow(false);
current.update();

}

Regards
Ankur

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

View solution in original post

20 REPLIES 20

Michael Jones -
Giga Sage

So, you want to set the attachment that is being displayed in an attachment type variable to be an attachment that already exists on the sys_attachment table? 

Get the sys_id of the attachment you want and set the value of the field with g_form.setValue('field_name', 'sys_id');

I hope this helps!

If this was helpful or correct, please be kind and remember to click appropriately!

Michael Jones - Proud member of the CloudPires team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

check these links and they should help you achieve with some enhancement

https://community.servicenow.com/community?id=community_question&sys_id=c400bf1ddb962450f21f5583ca96...

https://community.servicenow.com/community?id=community_question&sys_id=41af7501db1ea010fa192183ca96...

Regards
Ankur

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

Hi Ankur,

I have created a BR for automatically attaching the pdf of the form to the record after submitting the record so that the approver can go through the pdf.Now I want to copy that attachment to the field in the form instead of showing the attachment at the top of the form.

Hi Sarika,

update as this in the BR and set the attachment field name with the sys_id of the sys_attachment record

I assume this is before BR

var att = new GlideRecord('sys_attachment');

att.addQuery('table_sys_id', current.sys_id);

att.query();

if(att.next()){

current.attachment_fieldName = att.sys_id;

}

Regards
Ankur

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