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

Thanks buddy, It worked. I used variable inside coats"".   so silly..


Kudos Goran, this saved me. Cheers!

Hi Goran,

I have a requirement to copy parent ticket attachment and work notes to child ticket and Child ticket attachment and work notes to Parent ticket.

Note : we have same table for parent and child ticket.

 

I have written before update to copy parent attachment and work notes to child.

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

// Add your code here

var gr = new GlideRecord("sn_hr_core_case_workforce_admin");
gr.addQuery("parent", current.sys_id);
gr.addEncodedQuery('stateNOT IN3,4,7');
//gr.addQuery("sys_id", parent.sys_id);
gr.query();
while (gr.next()) {
new GlideSysAttachment.copy("sn_hr_core_case_workforce_admin", current.sys_id, "sn_hr_core_case_workforce_admin", gr.sys_id);
if(current.parent.nil()){
gr.work_notes = current.work_notes;
gr.comments = current.comments;
gs.addInfoMessage('Parent BR::'+current.comments);
gr.update();
}
}

Its working fine from parent to child  but i have created another BR for child to parent with same condition as before insert  with following code.

if (inc.get(current.parent)) {
new GlideSysAttachment.copy("sn_hr_core_case_workforce_admin", current.sys_id, "sn_hr_core_case_workforce_admin", inc.parent.sys_id);
inc.work_notes = "comment from " + current.number + ": " + current.comments;
inc.update();
}

 

But problem is work notes are updating as duplicate because BR Having same condition on same table.

I tried restricting to execute BR on condition wise like Parent is empty for child ticket update and Parent is empty for Parent ticket but its not working as expected.

 

Could you please help on this ?

 

Regards,

Pasha

Hi Pasha,

 

What you are getting is a loop since you are copying back and forward. What is the requirement that ends up with this solution? I can't understand the meaning of having all this copied and working in different cases. Sounds like you might as well just can work in the same case.

 

//Göran

Hi Goran,

 

Our requirement is to communicate in both ways as bidirectional like Parent ticket to child and child ticket to parent in HR Case.

Example .  Table name is : sn_hr_core_case_workforce_admin 

In this table both parent and child cases are storing.

 

So our requirement is like based on certain condition we are creating couple of child case automatically. in this case suppose if i am copying any attachment and comments or work notes then it should be copied to open child case only. similarly if i am commenting or attaching file from child case then it should copied on parent ticket. so to achieve this i had created  2 BR.

Regards,

Pasha