Copy attachment from table a to table b in scoped app

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 11:27 AM
I am trying to copy an attachment from one table to another table in a scoped application. I just can't get it to work. I checked the forum but I don't see what I do differently.
General description of what I am trying to do. I have a parent record that needs to create children for every user entered in the the list. That works perfect without a problem. I just can't copy the attachment(s) from the table that contains the parent record to the the children.
I also was thinking of creating just a http: link(s) to the attachments of the master record but I haven't done this before and would need some pointers.
Script:
Business Rule: Create activity records
When : after, Insert, Update.
(function executeRule(current, previous /*null when async*/) {
var list = current.u_responsible_party.toString();
var array = list.split(",");
for (var i=0; i < array.length; i++) {
if (array[i] != '') {
gr = new GlideRecord('x_conym_gov_req_activity');
gr.addQuery('u_request_number', '=', current.sys_id);
gr.addQuery('u_responsible_party', '=', array[i]);
gr.query();
if (!gr.next()) {
gr.u_request_number = current.sys_id;
gr.u_responsible_party = array[i];
gr.insert();
GlideSysAttachment.copy('x_conym_gov_request', current.sys_id, 'x_conym_gov_req_activity', gr.sys_id);
}
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 11:34 AM
Is your intention to just copy it and then it stays in the other record? If you the attachment was removed from the original table, do you want that attachment still visible in the other table?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 12:28 PM
Yes I just want to copy it. I don't want to remove it from the parent and yes I want to have it visible and available for other children in case the user adds more users to the list.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 12:26 PM
Yes I just want to copy it. I don't want to remove it from the parent and yes I want to have it visible and available for other children in case the user adds more users to the list.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2017 12:59 PM
try this http://wiki.servicenow.com/index.php?title=Copy_Attachments_from_Record_to_Record#gsc.tab=0
Although I do recommend rather than copying, you build a relationship between the children table and the attachment table so it displays the attachments. That way if the attachment is updated in the parent table, it shows the updated version in the children tables.