Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2026 04:00 AM
Hi @ronro2,
Business Rule setup:
Table: Incident (or your target table)
When: After
Insert: Checked
Condition: (leave empty)
(function executeRule(current, previous) {// Get the attachment variable valuevar attachmentVar = current.variables.bifoga_fil;if (!attachmentVar) {gs.info('No attachment found in bifoga_fil variable');return;}gs.info('Found attachment sys_id: ' + attachmentVar);// Method 1: Direct copy using GlideSysAttachmentvar sourceGr = new GlideRecord('sys_attachment');if (sourceGr.get(attachmentVar)) {var destTable = current.getTableName();var destSysId = current.getUniqueValue();gs.info('Copying to: ' + destTable + ' / ' + destSysId);// Create new attachment recordvar newAttach = new GlideRecord('sys_attachment');newAttach.initialize();newAttach.table_name = destTable;newAttach.table_sys_id = destSysId;newAttach.file_name = sourceGr.file_name;newAttach.content_type = sourceGr.content_type;newAttach.size_bytes = sourceGr.size_bytes;var attachId = newAttach.insert();// Copy the actual file datavar sourceDoc = new GlideRecord('sys_attachment_doc');sourceDoc.addQuery('sys_attachment', attachmentVar);sourceDoc.query();while (sourceDoc.next()) {var newDoc = new GlideRecord('sys_attachment_doc');newDoc.initialize();newDoc.sys_attachment = attachId;newDoc.data = sourceDoc.data;newDoc.insert();}gs.info('Attachment copied successfully!');}})(current, previous);