I have an issue with the Base64 Encoding in ServiceNow?

srirampappagudi
Tera Expert

Hi Experts,

In Knowledge Management, I am trying to read the attachments. When I pull a dump in XML and try to decode the

attachments it works fine. But when I use the REST API and pull the attachments, I am not able to decode the file it

throws an error. When I try to compare the Base64 String in XML and REST API, both are different. Kindly let me know

how to get this issue resolved.

Thank you,

Sriram.

 

 

1 ACCEPTED SOLUTION

Hi Sriram,

Yes the actual data resides in sys_attachment_doc but not as whole but in chunks; so you won't get complete set of data from that table from single record.

https://snprotips.com/blog/2016/2/25/understanding-and-using-glideattachment

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

View solution in original post

18 REPLIES 18

I recommend using the API, not any kind of Java code. This is the link to the scoped API (search for "attach"):
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_CertificateEnc...

there is also a global API as well as a REST API (https://developer.servicenow.com/dev.do#!/reference/api/orlando/rest/c_AttachmentAPI) for attachments.

Kind regards

Hi Sebastian,

I want to download attachments in a zip file according to the RITM no associated to it. I don't want to go with ui action option.

 

I tried to use attachment API but couldn't find a way to download the attachments. All i was able to see was metadata.

I want the exact attachment that is attached to the RITM

Example; if i have 20 RITMs. If i hot an API, then 20 zip files should be created locally storing the respective attachments.

 

Pls help.

 

Regards,

Nikita

sebastian_g_snc
ServiceNow Employee
ServiceNow Employee

Hi,

sys_attachment_doc is storing the attachment in base64 encoded chunks. So there is no real way to get the complete attachment except using the API. Sorry.

Kind regards

Vanjuli
Giga Contributor

Can someone help me with converting plain text content to base64encoded string. I need to convert text to encoded format write it into PDF with GlideSysAttachment API function :

writeBase64(GlideRecord now_GR, String fileName, String contentType, String content_base64Encoded)

Can't find any documentation or example to do so.