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

Phonsie Hevey1
Tera Expert

Hi,



This looks like it's the same problem as discussed in Any get GlideSysAttachment.write to work for binary files while in a scope?



Perhaps if you have access to an Istanbul instance you can see if it's been fixed as describe in the thread above.



Kind regards,



Phonsie


shivanipatel
ServiceNow Employee
ServiceNow Employee

Joseph,



We are glad you took advantage of the ServiceNow Community to learn more and to get your questions answered. The Customer Experience Team is working hard to ensure that the Community experience is most optimal for our customers.



If you feel that your question was answered, we would greatly appreciate if you could mark the appropriate thread as "Correct Answer". This allows other customers to learn from your thread and improves the ServiceNow Community experience.



If you are viewing this from the Community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thanks,


Shivani Patel


Unknown-1.png


Community Alums
Not applicable

Hi cap,

Could you please send me that working fine script fot text files. its argent 

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,


For creating a pdf, you have to use PDF generator code in service now. GlideSysAttachment wont create pdf for you,


Thanks,
Ashutosh

Community Alums
Not applicable

Hi Thanks for your reply please send that PDF generator code,and were it in servicenow