copy attachments from request to RITM

kunal16
Tera Expert

Hi,

I have a requirement to copy all the attachments from Request to the corresponding RITMs.

I have written an After-Insert Business rule on the Request table to achieve the same. But it seems the code is not working as expected.

Name: Copy Attachments to RITM

Table: Request (sc_request)

When to run: After - Insert

Script:

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

  // Add your code here

  var ritm = new GlideRecord('sc_req_item');

  ritm.addQuery('request', current.sys_id);

  ritm.query();

  while(ritm.next())

  {

  GlideSysAttachment.copy('sc_request', current.sys_id, 'sc_req_item', ritm.sys_id);

  }

})(current, previous);

Any lead will be appreciated. Thanks in advance!!

22 REPLIES 22

tanumoy
Tera Guru

Hi Kunal,



Let me know if you need any other assistance on this or please mark it as correct so that others with the same question in the future can find it quickly.


Hi Tanumoy,


This works perfectly in ServiceNow native view but not in Portal view (Helsinki version). Any thoughts? Do we need to create a new widget?


Hi Kunal,



I don't have much knowledge on Portal View. For business rule I don't think view will be an issue.


But the same thing is working for me in portal view (Geneva).


One more thing, I have done some changes in the script to overcome duplicate issue. You can try that :



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


   


  var ritm = new GlideRecord('sc_req_item');  


  ritm.addQuery('request', current.table_sys_id);  


  ritm.query();




    while(ritm.next())  


  {


  var gr = new GlideRecord('sys_attachment');


  gr.addQuery('table_sys_id', ritm.sys_id);


  gr.deleteMultiple();


  GlideSysAttachment.copy('sc_request', current.table_sys_id, 'sc_req_item', ritm.sys_id);


  }



})(current, previous);


Hi Tanumoy,



Thanks for the updated script - I already did that



But still the same issue - this is not working in Portal view (Service Portal, and not the ESS portal)


Hi Kunal,

Your requirement is exactly what I'm looking for, although the other way around.  Did you ever get the attachment to appear in the Portal view?

Thanks