add an attachment via catalog client script (on load). when i open the form it should add an attachment . i have written the below code but its ot working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2015 07:26 AM
function onLoad() {
//Type appropriate comment here, and begin script below
var cat_id = gel('sysparm_item_guid').value.toString();
//Check if attachment is available
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name','kb_knowledge');
gr.addQuery('file_name','test.dotx');
gr.query();
if(gr.next()){
GlideSysAttachment.copy('kb_knowledge','d826f8222d4cda40ac0a45db236a591d', 'sc_cart_item', cat_id);
}
}
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2015 07:32 AM
Could you explain the purpose behind this? Are you copying the same document to each record on a table? If it's for reference, why not just add a link to a KB article that has the attachment on it?
The reason your script doesn't work is because GlideSysAttachment is only available server side and a client script runs client side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2015 07:39 AM
requirement is : when i open the form it should have a document attached to it so that the user's can download the attachment for their reference and can edit it .

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2015 07:43 AM
I think you're a lot better off doing this with a KB with the attachment attached to it, then you can show a link to the kb article at the top of the form with a display business rule using gs.AddInfoMessage(). The advantage here is that you're not copying attachments all over the place and creating a bunch of duplicates.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2015 05:12 AM
Thanks brad for the idea! i tried to implement the what you suggested using a macro. Its working fine for me.
cheers!