The critical insight is that GlideSysAttachment.copy() creates a completely independent duplicate β€” both the attachment record and the underlying file data. Developers who try to manually duplicate by creating new sys_attachment records miss that the binary data lives separately in the platform's file store. This approach queries source attachments and processes them one at a time because you need each source sys_id for the copy operation.

When to use this

  • Business Rules that need to duplicate attachments when records are cloned or related
  • Scheduled Jobs that archive or migrate records with their attachments intact
  • Fix Scripts that need to bulk copy attachments between existing records
  • Template or parent-child workflows where child records inherit attachments

When NOT to use this

  • Don't use this in Client Scripts β€” attachments are server-side resources only accessible via GlideAjax
  • Don't use this for large attachment sets without considering storage quotas β€” each copy consumes additional disk space
  • Don't use this when you only need to reference attachments β€” use relationship fields instead of duplicating data

Key behaviors and gotchas

  • GlideSysAttachment.copy() returns the new attachment's sys_id on success, empty string on failure
  • The copy operation preserves original filename, content type, and file size but generates new sys_id and timestamps
  • Source attachments remain fully intact and readable β€” this is duplication, not a move operation
  • ACL enforcement applies to both source (read access) and target (write access) operations
  • Large files or high-volume operations can hit transaction timeouts β€” consider breaking into smaller batches
⚠️

The copy operation can silently fail if the target record doesn't exist or if you lack write access to the target table. Always check the return value and log failures β€” GlideSysAttachment won't throw exceptions for permission or missing record issues.

Free Newsletter

Enjoying this? Get one deep-dive per week.

Join 1,000+ ServiceNow pros β€” scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.

No spam Β· Unsubscribe anytime