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

Hi,

So is there attachment record attached to current record by the time the after BR runs?

how and from where you are adding file to this record?

Regards
Ankur

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

Thanks Ankur.its working. Actually i have created two BR for these.Now I added this script to the BR for automatic attachment  of pdf. Now its working

Hi @Ankur Bawiskar if i add a attachment in incident form need to automatically a checkbox is checked as true how can I do this? help me 

 

Hi @Ankur Bawiskar 

   I have a similar requirement like this but I need to copy the attachment to the record. How can do that? I'm using record producer and it has reference field which have attachments. I need to attach the attachment from the reference table to the record which is generating from Record producer. I'm using below script.

var att =  new GlideRecord('sys_attachment');
att.addQuery('table_sys_id', producer.document);
att.query();
if(att.next()){
    att.sys_id =  current.sys_id;
}
    current.insert();
 



@Avee678 

can you post a new question and share all the details as this is an old thread?

Tag me there

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