where can i find complete documentation about GlideStringUtil?

prasanna11
Mega Guru

Also what is the difference between

var StringUtil = new GlideStringUtil();

and this?

var StringUtil = GlideStringUtil ;

1 ACCEPTED SOLUTION

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:



areEqual ()Function
areEqualIgnoreCase ()Function
areNotEqual ()Function
arrayListToLines ()Function
base64Decode ()Function
base64DecodeAsBytes ()Function
base64Encode ()Function
charToNibble ()Function
cleanName ()Function
compress ()Function
contains ()Function
containsOneOf ()Function
decodeAttributes ()Function
decompress ()Function
dotToUnderBar ()Function
doubleQuotes ()Function
encryptPassword ()Function
escapeAllQuotes ()Function
escapeBackSlash ()Function
escapeDoubleQuotes ()Function
escapeForHomePage ()Function
escapeHTML ()Function
escapeLDAPDN ()Function
escapeNonPrintable ()Function
escapeQueryTermSeparator ()Function
escapeTicks ()Function
escapeTitle ()Function
fixSpecialQuotes ()Function
fromHexString ()Function
fromStringArray ()Function
getAlphaNumeric ()Function
getFirstWords ()Function
getHTMLValue ()Function
getNumeric ()Function
getRandomString ()Function
getStackTrace ()Function
getStringFromStream ()Function
getTimeSensitiveToken ()Function
hexFormat ()Function
isBase64 ()Function
isCaseEligibleSysID ()Function
isEligibleSysID ()Function
isHex ()Function
isLowerCaseHex ()Function
isMemberOf ()Function
isNumeric ()Function
isPositiveInteger ()Function
isWhiteSpace ()Function
join ()Function
makeEvalSafe ()Function
makeQuerySafe ()Function
maxLengthOfSize ()Function
newLinesToBreaks ()Function
nibbleTerm ()Function
nil ()Function
normalizeWhitespace ()Function
notNil ()Function
nullToEmpty ()Function
pad ()Function
padHex ()Function
padInt ()Function
pair ()Function
parseDouble ()Function
parseInt ()Function
parseLong ()Function
preserveLeadingSpaces ()Function
regexTransform ()Function
removeTrailingWhiteSpace ()Function
replaceAllNonAlphaNumeric ()Function
right ()Function
serializeAttributes ()Function
serializeDate ()Function
serializeProperties ()Function
setEscapeResolver ()Function
setProperties ()Function
simpleCleanName ()Function
sizeOf ()Function
split ()Function
stripNonNumbers ()Function
stripPrefix ()Function
stripSuffix ()Function
stripWhiteSpaces ()Function
subNil ()Function
subNull ()Function
substituteVariables ()Function
toArray ()Function
toBoolean ()Function
toDouble ()Function
toHexString ()Function
toSentenceCase ()Function
toStringArray ()Function
toTitleCase ()Function
toUpperFirst ()Function
toWords ()Function
trimQuotes ()Function
trimTrailing ()Function
truncateToUTF8Length ()Function
unEscapeHTML ()Function
unzip ()Function
urlDecode ()Function
urlEncode ()Function
urlSubstitute ()Function
urlUnwrap ()Function
urlWrap ()Function
zip ()Function


--


Cheers,


AR


View solution in original post

17 REPLIES 17

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?!


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


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


FYI - I have put in a request with development to get GlideStringUtil documented. No ETA yet.


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.