Servicenow fetch attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2024 06:06 AM
Hi,
Please help me with following query -
How do I fetch an attachment to use it somewhere else that is being attached to a new created record on ServiceNow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 04:15 AM
Hi @venkatk2, once the file is uploaded, you can copy it using this code:
var SOURCE_RECORD_ID = 'ABC';
var TARGET_RECORD_ID = 'DEF';
var SOURCE_TABLE = 'incident';
var TARGET_TABLE = 'sc_task';
new GlideSysAttachment().copy(SOURCE_TABLE, SOURCE_RECORD_ID, TARGET_TABLE, TARGET_RECORD_ID);
Please mark this response as useful and the question as solved if the issue has been solved. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 04:11 AM
Hi @p_kanczugowski ,
we are looking at using the attachment externally as part of api and are looking for a way to fetch the attachment Sys_ID from the record Sys_ID. thanks for the above response , we will test this for other use cases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 04:24 AM
Hi @venkatk2
Do you want to fetch the sys_id of the attachment on a record from a REST API call ?
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 04:29 AM - edited 03-12-2024 04:41 AM
Hi @venkatk2
Copy Attachment: Use this script
var attRec = new GlideRecord('sys_attachment');
attRec.addQuery('table_sys_id','sys_id');//sys_id of the record in which the attachment is attached
attRec.query();
while(attRec.next()){
//provide the table name and the reord sys_id to which you want to attach the copied attachment
new global.VariableUtil().copyAttachment(attRec.sys_id, 'table name', 'record sys_id');
}