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
03-21-2017 07:02 AM
There is an Attachment API: Attachment API
If you want to just do it in a script, there is a pretty good description of where things are stored here:Attachments in ServiceNow
JarodM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 11:05 AM
But what if i want to create the attachment? To my understanding, the attachment API doesn't create the file from scratch which is what I'd like to do.
As I said, the method i used in the original post works for text files, but i'd like to be able to create doc or pdf
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2017 11:39 AM
Im doing this from a business rule within the instance.
i have the payload and can encode it in base 64. I just want to know if there are options besides creating plain text.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2017 05:47 AM
Does the Attachment Creator REST API facilitate this?