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

manikorada
ServiceNow Employee
ServiceNow Employee

Josh,



On which table are you writing this business rule?


Hello Mani



I'm writing it against the Incident table after Incident is inserted


manikorada
ServiceNow Employee
ServiceNow Employee

Josh,



So, you would like to copy the attachments from the incident to the alert? is that right?


If so then the script will be :



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


gr.addQuery('u_incident', current.sys_id);     //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();


}


Hi Mani -



No, from the alert to the Incident