- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-29-2023 01:41 PM
Hello Experts,
We want to copy attachments from "sysapproval_approver" table to change request table.
i have created below GlideSysAttachment.copy code is working fine.
but issue is whenever record is inserted or updated copying all attachments every time.
Requirement1.If approver attachment should copy only one time.
Please support me on this
Table =sysapproval_approver
After insert or update BR.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var chg = new GlideRecord('change_request');
if(chg.get(current.sysapproval)){
var attachment = new GlideSysAttachment();
attachment.copy("sysapproval_approver",current.sys_id,"change_request",chg.sys_id);
}
})(current, previous
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-30-2023 11:25 PM
@akin9 condition is correct. Please try with below code.
var sy = new GlideRecord('sysapproval_approver');
sy.get(current.table_sys_id);
var changeSysID = sy.sysapproval;
var ch = new GlideRecord('change_request');
ch.get(changeSysID);
var attachment = new GlideSysAttachment();
attachment.deleteAll(ch);
attachment.copy("sysapproval_approver", current.table_sys_id, "change_request", changeSysID);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-29-2023 10:39 PM
Hello @SanjivMeher @Sandeep Rajput
We have tried the above code but no luck.
its not pasting the attachment and making instance as slow.
and we are getting like below multiple uploading image at same time?
can you pls check and correct me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-30-2023 11:27 AM
Ok. I dont think it is going to work, because the copy function copies everything from one record to another. And in you case there could be one or more attachments.
The other option would be to creating a relationship. Please refer the below link and refer the section 'All Request task and Approval Attachments'. That way you dont have to copy attachment. Everytime an attachment is attached, it can be seen in a related list in the parent record
https://servicenowguru.com/system-definition/relationships/defined-related-lists/
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-29-2023 11:04 PM
@akin9 Please use after insert BR on attachment table and select in condition table is Approval table and then write your code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-29-2023 11:21 PM
Hello @dhanu3 ,
Thanks for the quick reply,
I have tried but no luck pls correct me on more details.thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-30-2023 12:29 AM
Below code provided by Sanjiv should work. Please check how you are fetching change request sys id. As now you have BR on attachment table it will give you approval record sys id as table sys id. You have to fetch change request sys id.
var chg = new GlideRecord('change_request');
if(chg.get(current.sysapproval)){
var attchg = new GlideRecord('sys_attachment');
attchg.addQuery('table_name','change_request');
attchg.addQuery('table_sys_id',chg.sys_id);
attchg.addQuery('file_name',attapp.file_name)
attchg.query();
if (!attchg.next())
{
var attachment = new GlideSysAttachment();
attachment.copy("sysapproval_approver",current.sys_id,"change_request",chg.sys_id);
}
}