How can I create an attachment from script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2017 06:28 AM
Does SN offer any API to create an attachment? I've used the following:
var gsa = new GlideSysAttachment(); var attachmentId = sa.write(gr, "fileName.txt", 'text/plain', "some data");
This works fine for creating text files. It doesn't work when trying to create a pdf, doc or docx file. Is there a way to do so?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 09:57 PM
Hi gajji,
try using the below code snippet ,I hope this will help you.
var attach=new Attachment();
attach.write(tablename,rec sysid,filename,content type,value) ;
//here tablename is the table were you need to attach the attachment.
// rec sysID for the record on which you need to attach the attachment.
// File name is the name of attachment file with extentension like "filename.pdf".
//content type is the extenstion for file in your case it is "application/pdf".
//value is the base64 of the attachment file .
If Found helpful please mark as helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2018 05:56 AM
PDF Format
var gsa = new GlideSysAttachment();
var attachmentId = gsa.write(gr, "fileName.txt", 'application/pdf', "some data");
if it's correct above solution click helpful
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2022 12:47 AM
var gsa = new GlideSysAttachment();
You just need to add document type as the third parameter correctly. If it is docx then "application/docx" and if PDF then "application/pdf".
var cont_type = (documentType== "docx") ? "application/docx" : "application/pdf";
var attachmentId = sa.write(gr, "fileName.txt",cont_type , "some data");