How can I create an attachment from script?

Joey Wan Kenobi
Tera Guru

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?

22 REPLIES 22

jarodm
Mega Guru

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


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


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.


Does the Attachment Creator REST API facilitate this?