- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2016 07:18 AM
Also what is the difference between
var StringUtil = new GlideStringUtil();
and this?
var StringUtil = GlideStringUtil ;
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016 04:35 AM
Well prasanna,
GlideStringUtil is a global variable, its not a class. See Download Attachments as a ZIP File - ServiceNow Guru
To use GlideStringUtil:
var StringUtil = GlideStringUtil;
var sa = new GlideSysAttachment();
var binData = sa.getBytes(current);
var encData =StringUtil.base64Encode(binData);
There are a lot of useful functions in GlideStringUtil. These are:
--
Cheers,
AR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016 05:35 AM
Hi Akash,
Thanks for the detailed answer. But i can see below also works. (which means its an object ?)
var StringUtil = new GlideStringUtil();
Also just curious where did you find the documentation about this?!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016 05:54 AM
I never tried GlideStringUtil as a class. Coz when I tried it as a class, it is not giving me function list. I've tried GlideStringUtil as variable only.
Well, its very easy to find these functions. go to background script and run this code
var _gsu=GlideStringUtil;
for(var i in _gsu)
{
gs.print(i);
}
And it will give you all functions & properties.
--
Cheers,
AR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016 09:07 AM
var StringUtil = new GlideStringUtil();
for(var p in StringUtil )
{
if(typeof StringUtil[p] === "function") {
gs.print(p);
// its a function if you get here
}
}
this returned me these functions
*** Script: getClass
*** Script: wait
*** Script: hashCode
*** Script: equals
*** Script: notifyAll
*** Script: toString
*** Script: notify

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2016 02:44 PM
FYI - I have put in a request with development to get GlideStringUtil documented. No ETA yet.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2016 03:28 AM
FYI - This is the response I got from development.
Ultimately we don't want people working with raw bytes in JS, especially in scoped apps.
So there are two things that are going to go wrong with that script that Prasanna showed. 1 is GlideStringUtil, because we wouldn't want to expose decodeAsBytes either way. And also Attachment.write. The scoped version of Attachment.write currently only takes string content.
IF they already have a Base64 encoded string, then the easiest way for them to generate an attachment from that would be to use the SoapAttachment API. You can insert into the ECC queue directly (not actually using SOAP) with the base64 encoded attachment and it will generate the attachment for you.