Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Decode base 64 from Response body

Community Alums
Not applicable

I am trying to get the attachment from one of the end point, the attachment is  passed via base 64 encoded. I would like to know how to decode this and view this attachment. 

1 ACCEPTED SOLUTION

SwathiPedireddy
Kilo Sage

Hi @Community Alums 

Try following script according to your table

var attachment_name = ;//attachment name with extension
var contentType = ;//content type of the file(optional)

var incident_id = "sys_id of the incident";
var stringUtil = GlideStringUtil;
var attachment = new Attachment();
var value = attachment.write('incident', incident_id, attachment_name, contentType, stringUtil.base64DecodeAsBytes(base64 encoded string));

Thanks,

Swathi

View solution in original post

7 REPLIES 7

SwathiPedireddy
Kilo Sage

Hi @Community Alums 

Try following script according to your table

var attachment_name = ;//attachment name with extension
var contentType = ;//content type of the file(optional)

var incident_id = "sys_id of the incident";
var stringUtil = GlideStringUtil;
var attachment = new Attachment();
var value = attachment.write('incident', incident_id, attachment_name, contentType, stringUtil.base64DecodeAsBytes(base64 encoded string));

Thanks,

Swathi

Community Alums
Not applicable

Hi Swathi,

 

1) I'm able to decode the base64 to binary data using the below code in screenshot . Can you help me to know what should I do next

JishnuJ_0-1736313039941.pngJishnuJ_1-1736313077749.png

JishnuJ_2-1736313138401.png

 

 

 

 

Community Alums
Not applicable

Thank you Swathi, this worked for me