Convert String to Bytes using UTF-8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2023 02:17 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2023 07:20 PM - edited 07-15-2023 07:21 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2023 11:22 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2023 12:27 PM
@Surbhi Srivasta For scoped app, then Samaksh provided the correct solution.