How to attach one attachment to several records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 12:46 PM - edited 05-17-2024 12:48 PM
Hey all,
We have a situation where we want to attach information from a manufacturer to multiple hardware model lifecycle phases as evidence of a hardware lifecycle date. The issue we're running into is that we don't have an out of the box approach (that we've seen) that will let us attach the evidence to multiple hardware model lifecycle phases. Anyone else run into something similar or have a solution?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2024 01:14 AM
Hello @HAM_MAN ,
ServiceNow OOTB doesn't have built-in functionality to automatically attach files from one table to another.
Instead, you can explore GlideSysAttachment
https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server/no-namespace/c_GlideSysA...
Moreover, this post can help you, it involves scripting but you have the reference so it is not that difficult.
https://www.servicenow.com/community/developer-forum/copy-attachments-from-one-record-to-another/m-p...
Please mark helpful to the response if it has helped you
Thanks
Amarjeet Pal
Advania UK
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2024 02:08 AM
Hi @HAM_MAN ,
You can call the below script include from Scheduled Job or some other way as per your requirement by passing source table name, source sysid, target Table name, comma separated target sysid's,
Script Inculde:
var AttachmentUtils = Class.create();
AttachmentUtils.prototype = {
initialize: function() {},
copyAttachmentToRecords: function(sourceTableName, sourceSysId, targetTtableName, targetSysIds) {
// Loop through the target records and attach the file
var targetSysIdArray = targetSysIds.split(',');
for (var i = 0; i < targetSysIdArray.length; i++) {
var targetSysId = targetSysIdArray[i];
new GlideSysAttachment().copy(sourceTableName, sourceSysId tableName, targetSysId);
}
},
type: 'AttachmentUtils'
};
I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.