Attachment failed

akin9
Tera Contributor

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.

 

 

(function executeRule(current, previous /*null when async*/) {
 
// Add your code here
 
var chg = new GlideRecord('change_request');
chg.get(current.sysapproval);
GlideSysAttachment.copy("sysapproval_approver",current.sys_id,"change_request",chg.sys_id);
    current.update();
 
 
})(current, previous);

 

 

 

 

9 REPLIES 9

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);

Sandeep Rajput
Tera Patron
Tera Patron

@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);
 

 

Hi @Sandeep Rajput ,

Its working fine, can we add copy comments on the same?

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.

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);