Copy attachment from one table to another table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 03:17 AM
Hi,
I created 1 custom table, in that I have created 3 fields- 1. Asset tag 2. serial no. 3. File attachment, for testing purpose I have created 2 records, I want to copy that attachment(with respect to same asset tag record on asset table) and attach into alm_asset table.
I need to create scheduled job for this, whenever i execute that scheduled job, all attachments copied from custom table to asset table with same asset tag records.
Please help me with code
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 03:25 AM
Hi Aishwarya,
Use the GlideSysAttachment:
var copyAtt = new GlideSysAttachment();
copyAtt.copy(<source_table>,<source_record_SysID>, <target_table>,<target_table_SysID>);
This should do the trick for you!!
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 05:10 AM
but how can i map to the correct asset tag?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 08:05 AM
Hello Aishwarya,
In your scheduled job, when you iterate through your custom table records, you will need to do something like:
var ct = new GlideRecord(custom_table);
ct.addQuery(<you_query_here>);
ct.query();
while(ct.next()){
var asset = new GlideRecord("alm_asset");
asset.get(sys_id_of_asset);
asset.asset_tag = ct.asset_tag; //check field names!
//copyAttachments
var copyAtt = new GlideSysAttachment();
copyAtt.copy(<source_table>,<source_record_SysID>, <target_table>,<target_table_SysID>);
}
I cannot help more than this since I don't know the data structure of your tables, but I believe from here you will be able to finish your scheduled job.
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Best Regards,
Filipe Cruz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2022 11:52 PM
Thanks for your code, but how can i sent multiple sys id's in GlideSysAttachment function?
There are multiple sys id's i need to pass...
copyAtt.copy(u_staging_table_for_attachhment,ct.sys_id,alm_asset,sys);