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

Copying attachments - not working

Josh80
Tera Expert

Hi...

I've researched the wiki and I believe I have a Business Rule that should work for my requirement, but it is not.

I've used this Wiki article:

copy attachments from one task to another

To build this - However, it is not working.   Any suggestions?   Thank you!

(Note: We have a custom 'alert' table that was implemented before 'event mgmt' was created.

Alerts are inserted into this table; the NOC then creates Incidents off of these Alerts.

So, on the Alert record there is a custom field 'u_incident' which contains the number of the Incident that is generated from the Alert.

the Alert is in the related list on the only created Incident.)

==============

function onAfter(current, previous) {

var gr = new GlideRecord('u_alert');   //query the customer alert table

gr.addQuery('sys_id', current.u_incident);     //look for the sys_id of the current incident record in the 'u_incident' field on the Alert record

gr.query();

while(gr.next()) {

GlideSysAttachment.copy("incident", current.sys_id, "u_alert", gr.sys_id);     //copy the attachment to the current incident from the alert record that was queried

  gr.update();

}

}

===============

1 ACCEPTED SOLUTION

Ok - so there's something else going on.



I changed the business rule to pull the attachment 'on update' and it works with this script:


var gr = new GlideRecord('u_alert');


gr.addQuery('u_incident', current.sys_id);    


gr.query();


while(gr.next()) {


GlideSysAttachment.copy("u_alert", gr.sys_id, "incident", current.sys_id);


  gr.update();


}  


}



The reason the on 'insert' isn't working has something to do with the face we're running the script from a UI page 'processor' instead of directly from the UI action.   I have to figure out how to have the UI page do it vs. just the UI action.



Thank you all for responding and your assistance!


View solution in original post

14 REPLIES 14

Hi Josh,



You have to write a BR on alert table and replace your complete script with only one line as.


GlideSysAttachment.copy("u_alert", current.sys_id, "incident", current.u_incident.sys_id);     //copy the attachment to the current incident from the alert record that was queried


Pradeep,



It needs to run when the Incident is inserted...First the Alert must be inserted with attachment, then 'create incident' is selected which inserts the new Incident, copying attachment from Alert.



Thanks


Josh


Looks like you have it reversed...the wiki shows from source to destination:



GlideSysAttachment.copy('sourcetable', 'sys_id', 'destinationtable', 'sys_id')


;


Hi Victor



Thank you - Yes, I've already tried it but no dice.


Thanks


Josh


I am also facing the same issue. I have a before Insert BR on the Incident table with the following script and nothing happens when I save the incident. All help is appreciated.



GlideSysAttachment.copy('incident', 'current.sys_id', 'sys_template', 'current.sys_id');