Streamlining Attachment Management in ServiceNow: Using GlideSysAttachment.copy
- nathanlee142
- May 13
- 4 min read

ServiceNow often requires the ability to manage attachments across different records. Whether it's copying supporting documents from a parent incident to a child request or transferring files between related records, efficiently handling attachments is key to maintaining data consistency and streamlining workflows. ServiceNow provides a powerful server-side API called GlideSysAttachment that allows developers to programmatically manage attachments. This article will focus on the copy() method of this class and demonstrate how it can be effectively used within ServiceNow Business Rules, even on tables other than the sys_attachment table itself. This capability is particularly useful for automating attachment-related tasks based on specific record events or conditions.
The GlideSysAttachment class in ServiceNow offers several methods for interacting with attachments. The copy() method is particularly useful when you need to duplicate attachments from one record to another. A common question among ServiceNow developers is whether this method can be invoked within Business Rules that are not running on the sys_attachment table. The answer is a resounding yes. You can absolutely use GlideSysAttachment.copy() in Business Rules running on tables like incident, sc_req_item, or any other table that can have attachments.
Understanding the GlideSysAttachment.copy() Method
The copy() method takes four arguments:
Source Table Name: The name of the table containing the attachment(s) you want to copy (e.g., 'incident', 'sc_req_item').
Source Record Sys ID: The unique identifier (sys_id) of the specific record from which you want to copy the attachment(s).
Target Table Name: The name of the table where you want to copy the attachment(s) to (e.g., 'incident', 'sc_req_item').
Target Record Sys ID: The unique identifier (sys_id) of the specific record where you want to copy the attachment(s).
Example 1: Copying Attachments Between Two Specific Records (Incident to Incident)
Let's say you need to copy all attachments from one incident record to another. You would use the following script within a Business Rule (ensure you replace the sys_ids with your actual record sys_ids):
JavaScript
var sourceSysID = 'YOUR_SOURCE_INCIDENT_SYS_ID';
var targetSysID = 'YOUR_TARGET_INCIDENT_SYS_ID';
var copyAtt = new GlideSysAttachment();
copyAtt.copy('incident', sourceSysID, 'incident', targetSysID);
Example 2: Copying Attachments from a Parent Record to the Current Record (e.g., Parent Incident to Child Incident)
In scenarios involving parent-child relationships, you might want to automatically copy attachments from the parent record to the newly created child record. Assuming your current record (the child incident) has a field named parent_incident that references the parent incident, you can use the following script in a Business Rule that runs on the child incident table (e.g., 'before insert'):
JavaScript
var copyAtt = new GlideSysAttachment();
var parentIncidentSysID = current.getValue('parent_incident'); // Get the sys_id of the parent incident
if (parentIncidentSysID) {
copyAtt.copy('incident', parentIncidentSysID, 'incident', current.getUniqueValue());
}
Here, current.getUniqueValue() retrieves the sys_id of the current record (the child incident).
Example 3: Copying Attachments from a Catalog Item Request Item to the Corresponding Task
Consider a scenario where a user uploads attachments to a catalog item request. You might want to copy these attachments to the associated Request Item Task (sc_task). You could achieve this using a Business Rule on the Request Item (sc_req_item) table that triggers when the Request Item Task is created:
JavaScript
var ritmSysID = current.sys_id; // Sys ID of the Request Item (source)
var taskSysID = current.getValue('sys_id'); // Sys ID of the current Request Item Task (target) - Assuming this BR runs on sc_task
var copyAtt = new GlideSysAttachment();
copyAtt.copy('sc_req_item', ritmSysID, 'sc_task', taskSysID);
Important Considerations
Business Rule Timing: Choose the appropriate "When to run" setting for your Business Rule (e.g., 'before insert', 'after insert', 'before update', 'after update') based on when you need the attachments to be copied.
Performance: For operations that might involve a large number of attachments, consider making your Business Rule asynchronous to prevent blocking other processes.
Error Handling: While not explicitly shown in the examples, in a production environment, you might want to add error handling to manage potential issues during the attachment copying process.
Source Record Identification: Ensure you are correctly identifying the sys_id of the source record from which you want to copy the attachments. This might involve querying other tables using GlideRecord to find the appropriate record.
Alternative Solutions
While GlideSysAttachment.copy() is the most direct way to duplicate attachments programmatically, you could also explore other options depending on your specific requirements:
Manual Copying: Users can manually download and re-upload attachments if the frequency of copying is low.
Workflows or Flows: For more complex scenarios, you could incorporate attachment copying logic into a Workflow or Flow using script activities or potentially out-of-the-box actions if available for your specific use case.
Conclusion
The GlideSysAttachment.copy() method is a versatile tool for managing attachments in ServiceNow. Its ability to copy attachments between records of different tables makes it invaluable for automating various attachment-related tasks within Business Rules. By understanding the syntax and providing the correct source and target table names and record sys_ids, ServiceNow developers and administrators can significantly enhance their ability to manage and propagate information effectively across the platform. The next step is to identify scenarios in your ServiceNow environment where automating the copying of attachments could improve efficiency and data consistency, and then implement the appropriate Business Rules using GlideSysAttachment.copy().