Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Convert String to Bytes using UTF-8

Surbhi Srivasta
Tera Expert

Hi,

I am stuck at an issue where I need to convert a String into Bytes using UTF-8 format to be sent to a 3rd party application. 3rd party application only support parameters in this format.

Any pointers on how we can do this. 

 

Regards,

Surbhi

7 REPLIES 7

shawna
Tera Guru

You can try this. I tested this in the background script. 

 

var str = "Hello, World!";
var utf8Bytes = GlideStringUtil.base64DecodeAsBytes(GlideStringUtil.base64Encode(str));
gs.print(str + utf8Bytes);

@shawna 

I need to do the above conversion in a scoped app. Unfortunately the above code did not worked for a scoped app. My apologies of not mentioning this in my post earlier . Any thoughts on what would be the alternative?

 

Regards,

Surbhi

shawna
Tera Guru

@Surbhi Srivasta For scoped app, then Samaksh provided the correct solution.