The CreatorCon Call for Content is officially open! Get started here.

Script is copying multiple times

akin9
Tera Contributor

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

 

1 ACCEPTED SOLUTION

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

View solution in original post

26 REPLIES 26

akin9
Tera Contributor

Hello @dhanu3 ,

Hope is it Table = sys_attachment

After insert/update   BR

After insert BR on sys_attachment table and in condition select table name is sys_approval and then you code to get sys id of change request and to copy attachment

akin9
Tera Contributor

Hello @dhanu3,

I have tried the same but no luck.

can you pls check

 

akin9_0-1701340297089.png

 

 

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

akin9
Tera Contributor

Hello @dhanu3 ,

After insert - 

 after insert on sys_attachment

Condition: current.table_name == 'sysapproval_approver'

 

I have followed the above working fine.

 

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

// Add your code here
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);

})(current, previous);