Attachment failed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 01:45 AM
Hello Experts,
We want to copy attachment from "sysapproval_approver" table to change request table.
We have created after insert br tried below code but its not working ,
please support to fix the issue.
After insert BR.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 04:25 AM
Hi @AnveshKumar M ,
Thanks for the support! im using below script is working fine.
(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);
chg.comments = current.comments.getJournalEntry(1);
current.setWorkflow(false);
current.update();
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 02:50 AM - edited 09-28-2023 04:26 AM
@akin9 Update your code as follows and check if it works for you.
(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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 04:16 AM
Hi @Sandeep Rajput ,
Its working fine, can we add copy comments on the same?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 04:24 AM
Yes you can use the following code to copy the comment.
(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);
chg.comments = current.comments.getJournalEntry(1);//1 fetches the lastest comment and -1 fetches all comments
chg.update();
}
})(current, previous);
Please don't forget to mark the answer correct and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-28-2023 01:07 PM
Hello @Sandeep Rajput
Sorry its not working ! pls check
and i have created two BR one for comments and another one is for attachment working
but issue is all the attachments repeating.
Comments.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var cr = new GlideRecord('change_request');
cr.get(current.sysapproval);
cr.comments = current.comments.getJournalEntry(1);
cr.update();
})(current, previous);
Attachments.
(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);