The CreatorCon Call for Content is officially open! Get started here.

To get attachment file name

Raji9
Tera Expert

Hi All,

While copying the attachment from one record to another record using attachment.copy , How to get file name of the attachment.

 

Thanks

Ra

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Raji9 ,

You can Configure a after insert business rule on sys_attachment table and using getContentStream() and writeContentStream() methods to create an attachment on the target record.

 

Please refer to the sample Script in the Article : https://www.servicenow.com/community/itsm-articles/copying-attachment-from-one-record-to-another-rec...

 

View solution in original post

4 REPLIES 4

Mark Manders
Mega Patron

What do you need the name for? It's just a one-on-one copy, adding it to another record. 
But the name of the attachment is in the 'file_name' field on the record.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Community Alums
Not applicable

Hi @Raji9 ,

You can Configure a after insert business rule on sys_attachment table and using getContentStream() and writeContentStream() methods to create an attachment on the target record.

 

Please refer to the sample Script in the Article : https://www.servicenow.com/community/itsm-articles/copying-attachment-from-one-record-to-another-rec...

 

Sumanth16
Kilo Patron

Hi @Raji9 ,

 

 

var gr = new GlideRecord('sys_attachment');

 

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

 

gr.query();

 

if(gr.next()){//use `while` if dealing with multiple attachments

 

  if(gr.getValue('file_name').indexOf('xlsx') != -1 && gr.getValue('file_name').indexOf('myfile') != -1){//meaning if you find a file with xls extension

 

  //do something

 

  }

 

}

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

swathisarang98
Giga Sage

Hi @Raji9 ,

 

You can refer below articles,

 

https://www.servicenow.com/community/developer-forum/to-get-attachment-file-name-and-file-format/m-p... 

https://www.servicenow.com/community/itsm-forum/get-attachment-file-name/td-p/642891 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang