GlideSysAttachment.copy

sarfraz3
Mega Expert

Can we write GlideSysAttachment.copy in business rule which does not runs on sys_attachment table?.. Or it can be only written on sys_attachment table?.

I have been trying to write it on sc_req_item table.. but it does not copy the attachment!

1 ACCEPTED SOLUTION

Here is an example, copying attachments from one incident record to another.



var sourceSysID = '9c573169c611228700193229fff72400';


var targetSysID = '9d385017c611228701d22104cc95c371';



var copyAtt = new GlideSysAttachment();


copyAtt.copy('incident',sourceSysID, 'incident',targetSysID);



If it was in a a br and I want to copy from lets say to current incident record to the record in the parent incident field it could look like this:



var copyAtt = new GlideSysAttachment();


copyAtt.copy('incident',current.getUniqueValue(), 'incident',current.getValue('parent_incident'));



And make this a async BR for performance.


View solution in original post

15 REPLIES 15

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

yes, you can use the function on other tables.. can you show us the code you done?


when to run:


before insert


order= 100


table: sc_req_item



script:


var id=current.variables.psa_ritm_id;   // this is a variable in the catalog item form which gives the ID of the RITM which has the attachment  


gs.log(' id in Url '+id);



if(id){ // if id is present


gs.log('current id '+current.sys_id);


GlideSysAttachment.copy('sc_req_item', 'id', 'sc_req_item', 'current.sys_id'); //copy the attrachment


}


did a few changes. I take that the variable holds the sys_id of the source record. and not a number like RITM002343



var id=current.variables.psa_ritm_id;   // this is a variable in the catalog item form which gives the ID of the RITM which has the attachment


gs.log(' id in Url '+id);



if(id){ // if id is present


gs.log('current id '+current.sys_id);
var copyAtt = new GlideSysAttachment();


copyAtt.copy('sc_req_item', id, 'sc_req_item', current.getUniqueValue()); //copy the attrachment


}


Here is an example, copying attachments from one incident record to another.



var sourceSysID = '9c573169c611228700193229fff72400';


var targetSysID = '9d385017c611228701d22104cc95c371';



var copyAtt = new GlideSysAttachment();


copyAtt.copy('incident',sourceSysID, 'incident',targetSysID);



If it was in a a br and I want to copy from lets say to current incident record to the record in the parent incident field it could look like this:



var copyAtt = new GlideSysAttachment();


copyAtt.copy('incident',current.getUniqueValue(), 'incident',current.getValue('parent_incident'));



And make this a async BR for performance.