- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2016 07:56 AM
Hi,
I would like an attachment (word document) to be attached to each new record (in my request table) by default, as soon as the record gets created. How would I do this?
Right now I have to drag-and-drop the attachment onto each record.
Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2016 09:36 AM
Hi,
You can upload attachment in sys_attachment table and then create a before business rule on incident table to copy attachment from sys_attachment table to incident table with the help of GlideSysAttachment.copy
More info here Copy Attachments from Record to Record - ServiceNow Wiki

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2016 09:36 AM
Hi,
You can upload attachment in sys_attachment table and then create a before business rule on incident table to copy attachment from sys_attachment table to incident table with the help of GlideSysAttachment.copy
More info here Copy Attachments from Record to Record - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2016 10:40 AM
But can I select which attachments to copy? GlideSysAttachment.copy seems to copy all attachments over it says.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2016 10:59 AM
Yes you can select which attachment to be copied. Pass source table and sys_id parameters i.e sys_attachment table and sys_id of the attachment record.
Please let me know if you have any questions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2016 12:34 PM
I believe GlideSysAttachment.copy will not work when you are trying to copy from sys_attachment table directly. Instead you will have to query on the attachment table and find the attachment record you want to insert on all the requests and insert a new attachment in the sys_attachment table using a before business rule.
Note: The downside of it is you will end up creating a duplicate each time a request is inserted
Create a new business rule on sc_request table
when: before insert
Script:
var attachmentGR= new GlideRecord('sys_attachment');
attachmentGR.addQuery('file_name','<your file name goes here>'); //put your file name here
attachmentGR.query();
if(attachmentGR.next()){
var newGR = new GlideRecord('sys_attachment');
newGR.initialize();
newGR.compressed = attachmentGR.compressed;
newGR.content_type = attachmentGR.content_type;
newGR.size_bites = attachmentGR.size_bites;
newGR.size_compressed = attachmentGR.size_compressed;
newGR.file_name = attachmentGR.file_name;
newGR.table_name = current.getTableName();
newGR.table_sys_id = current.getValue('sys_id');
var newID = newGR.insert();
}