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

AnveshKumar M
Tera Sage
Tera Sage

Hi @akin9 

 

Try the following code.

(function executeRule(current, previous /*null when async*/) {

   var attachment = new GlideSysAttachment();
   attachment.copy('sysapproval_approver', current.sys_id, 'change_request', current.getValue('sysapproval'));

})(current, previous);

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

Thanks,
Anvesh

Hello @AnveshKumar M ,

Thank you for the Quick reply!

I have tried the above code but no luck. Please check

 

 

akin9_0-1695894601229.png

 

NOTE: I have tried the for the same copy comments its working fine.

(function executeRule(current, previous /*null when async*/) {
 
// Add your code here
var chg = new GlideRecord('change_request');
chg.get(current.sysapproval);
chg.comments = current.comments.getJournalEntry(1);
chg.update();
 
})(current, previous);

Hi @akin9 

Are you trying to copy the attachments after the approval is approved or whenever an attachment is added?

 

And have you checked both Insert and Update fields to true in the Business Rule when to run tab or only insert? If it is only Insert, make Update also checked.

 

Mean while I'll check this in my PDI.

Thanks,
Anvesh

Hi @akin9 

I tested this in my PDI, It is working fine with the below configuration. Only exception is you need to update the approval record, either approve it or reject it etc,

 

If you want it to work whenever the attachment is added, let me know, I'll give the code accordingly.

 

AnveshKumarM_0-1695898297217.png

 

AnveshKumarM_1-1695898317816.png

 

Thanks,
Anvesh