How to copy attachments from RITM to Incident

kutvaram
Tera Expert

I have used the following script in BR after insert :

GlideSysAttachment.copy("sc_req_item", current.request_item.sys_id, "incident", current.sys_id);

But it is not working.

Please do the needful.

Regards,
Ram Prakash

1 ACCEPTED SOLUTION

Thank you. That indicates that the incident is using the parent field to point to the RITM record. In that case, your business rule should be able to copy the attachment from the RITM to the incident record using the copy command I gave earlier if everything else is working properly.



GlideSysAttachment.copy("sc_req_item", current.parent, "incident", current.sys_id);



If not, please use the business rule debugger to ensure your business rule is triggering, or debug statements in your UI action (if that is how you are copying the file.) You may also find this video helpful for debugging:



Faster Server Side Script Development and Test


View solution in original post

16 REPLIES 16

Chuck Tomasi
Tera Patron

Hi Ram,



What does the rest of your business rule look like? Specifically, what table is it running on? Incident?



If that's the case, then there is no default request_item on the table. Perhaps it should be u_request_item? Is there a request item field on the incident that relates these two together or are you looking to copy from some other "random" request item?



Also, you don't need to dot-walk to a sys_id of a reference field. The reference field value is already a sys_id. Going on my assumptions, your code may look a bit more like this:



GlideSysAttachment.copy("sc_req_item", current.u_request_item, "incident", current.sys_id);



No guarantee of success until I know more about the larger context of the table involved and field names.


Hello Chuck,



BR is running on "Incident" Table.



This is the only code present in that.



I have tried your suggestion. No success.



Regards,
Ram


Hi Ram,



What is the relationship between the incident and the request item? Your script indicates there is a reference field on the incident record called requsted_item. Clearly that is not the case. In order to help, I need additional information how these two tables are connected? There needs to be a way to find that specific request item's attachment.


Hello Chuck,



Incident has been created using workflow (Create Task   Activity).



That is the only relationship I can see here.



I tried to achieve the copy attachment using the following link:



https://community.servicenow.com/thread/193788?q=How%20to%20copy%20attachments%20from%20RITM%20to%20...



But this also not worked.



Regards,


Ram