Create Attachment from Content SStream

Saran Ramayanam
Tera Expert

Hi EveryOne, 

 

I am getting StreamContent of an attachment in response body of ecc, Can any one let me know how to create an attachment from that ??

to Use New GlideSysAttachment().writeContentStream(gr,FILENAME,CONTENTTYPE,GlideScriptableInputStream stream)

the stream should be an object, i am unable to convert this response body i got into an object

 

 

Regards

Saran

4 REPLIES 4

AbhishekGardade
Giga Sage

Hello Saran,

I have used below script. check for your reference. What is your test case?

var StringUtil = GlideStringUtil;
var attachment = new Attachment( );
attachment.write('incident',target.sys_id,source.u_attachment_name,'',StringUtil.base64DecodeAsBytes(source.u_attachement_file));

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Saran,

for creating attachments in ServiceNow you need to get the base64encoded data; then you can SOAP attachment creator for that and attachment will be added by system

what error you are getting when you are using that?

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

HI Anukur, 

 

Some third party tool is sending stream content, basically it is binary, need to find a way to coinvert this to base64 or GlideScriptableObject to create an attachment

Hi Saran,

I don't think this would work with binary data. try telling them to send base64encoded data.

If I find anything will post.

Regards

Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader