GlideStringUtil - Scoped, Global

concept australia Updated Sep 10, 2026 4 min read GlideStringUtilScopedAPI.md
Raw file servicenow.com

The GlideStringUtil API provides string handling methods.

Access these methods using the static object GlideStringUtil. This class is available in scoped and global scripts.

Parent Topic:Server API reference

GlideStringUtil - dotToUnderBar(String sourceString)

Replaces periods with underscore characters.

Name Type Description
sourceString String Text to process.
Type Description
String Text with periods replaced with underscores.
JavaScript
var filename="../../../../../../etc/passwd";cleanFilename=GlideStringUtil.dotToUnderBar(filename);gs.info(cleanFilename);

Output:

Text
 __/__/__/__/__/__/etc/passwd

GlideStringUtil - escapeAllQuotes(String sourceString)

Removes quotes from a string.

Name Type Description
sourceString String The string to be processed.
Type Description
String The string with quotes removed.
JavaScript
mystring="let's escape some quotes";escapeQuote=GlideStringUtil.escapeAllQuotes(mystring);gs.info(escapeQuote);

Output:

Text
lets escape some quotes

GlideStringUtil - escapeForHomePage(String sourceString)

Replaces problem characters with escape characters.

Name Type Description
sourceString String Text to process.
Type Description
String Text with problem characters replaced with escape characters.
JavaScript
mystring="<test> string \n to escape";escapedString=GlideStringUtil.escapeForHomePage(mystring);gs.info(escapedString);

Output:

Text
%3ctest%3e string \n to escape

GlideStringUtil - escapeHTML(String htmlString)

Replaces illegal characters with their escape codes.

Using this method removes illegal characters that might cause the UI to render improperly, or trigger a client side attack such as JavaScript or HTML injection.

Name Type Description
htmlString String Text to process.
Type Description
String Text with illegal characters replaced with their escape codes.
JavaScript
mydata='"<>&';mydata=GlideStringUtil.escapeHTML(mydata);gs.info(mydata);

Output:

Text
&quot;&lt;&gt;&amp;

GlideStringUtil - escapeNonPrintable(String sourceString)

Replaces non-printable characters with their printable notation.

Name Type Description
sourceString String Text to process.
Type Description
String Text with non-printable characters replaced with printable notation.
JavaScript
mystring="test \x09 non \x00 printable \x07 chars";escapedString=GlideStringUtil.escapeNonPrintable(mystring);gs.info(escapedString);

Output:

Text
test \t non \u0000 printable \u0007 chars

GlideStringUtil - escapeQueryTermSeparator(String sourceString)

Replaces query term separators "^" with their escape sequence "^^".

Name Type Description
sourceString String Text to process.
Type Description
String Text with query term separators replaced with the escape characters.
JavaScript
myquery="test^Test";escapedQuery=GlideStringUtil.escapeQueryTermSeparator(myquery);gs.info(escapedQuery);

Output:

Text
test^^Test

GlideStringUtil - escapeTicks(String sourceString)

Replaces quotes with escape characters by adding a backslash before each quote.

Name Type Description
sourceString String Text to process.
Type Description
String Text with backslashes added before quotes.
JavaScript
mystring="let's try escapeTicks";escaped=GlideStringUtil.escapeTicks(mystring);gs.info(escaped);

Output:

Text
let\'s try escapeTicks

GlideStringUtil - getHTMLValue(String sourceString)

Replaces illegal HTML characters into HTML notation.

Using this method removes illegal characters that might cause the UI to render improperly, or trigger a client side attack such as JavaScript or HTML injection.

Name Type Description
sourceString String Text to process.
Type Description
String Text with illegal characters replaced with HTML notation.
JavaScript
mydata='&';htmlvalue=GlideStringUtil.getHTMLValue(mydata);gs.info(htmlvalue);

Output:

Text
&amp;

GlideStringUtil - getNumeric(String sourceString)

Extracts numeric characters from a string.

Name Type Description
sourceString String Text to process.
Type Description
String Text containing only numeric characters.
JavaScript
mystring='123 test 456 String 789 cleaning';onlyNumeric=GlideStringUtil.getNumeric(mystring);gs.info(onlyNumeric);

Output:

Text
123456789

GlideStringUtil - isBase64(String sourceString)

Validates whether the specified string is a valid base64 string.

Name Type Description
sourceString String Text to process.

Type

Description

Boolean

Flag that indicates whether the specified string is in valid base64 format.Possible values:

  • true: Valid base64 formatted string.
  • false: Invalid base64 formatted string.
``` //(adding a "*" to corrupt the base64 format) base64="GethdTYehdtshetB*"; isValid=GlideStringUtil.isBase64(base64); gs.info(isValid); ```

Output:

Text
false

GlideStringUtil - isEligibleSysID(String sourceString)

Validates whether the specified string is in valid sys_id format.

The sys_id format is a sequence of 32 hexadecimal characters where all the characters are in the range [0-9, a-f, A-F].

Name Type Description
sourceString String Text to process.

Type

Description

Boolean

Flag that indicates whether the specified string is in valid sys_id format.Possible values:

  • true: Valid sys_id formatted string.
  • false: Invalid sys_id formatted string.
``` sysID="62826bf03710200044e0bfc8bcbe5df1"; isElig=GlideStringUtil.isEligibleSysID(sysID); gs.info(isElig); ```

Output:

Text
true

GlideStringUtil - newLinesToBreaks(String sourceString)

Replaces the new line character, /n, with a break code, <br/>.

Name Type Description
sourceString String Text to process.
Type Description
String Text with new line characters replaced with HTML break code.
JavaScript
mystring="new line break \n, this is after the break";replaceNewLine=GlideStringUtil.newLinesToBreaks(mystring);gs.info(replaceNewLine);

Output:

Text
new line break <br/>, this is after the break

GlideStringUtil - normalizeWhitespace(String sourceString)

Replaces carriage returns, line feeds, and tabs with spaces, and then removes leading, trailing, and duplicate spaces.

Name Type Description
sourceString String Text to process.
Type Description
String Text with carriage returns, line feeds, and tabs replaced with spaces, and then leading, trailing, and duplicate spaces removed.
JavaScript
mystring="test with \n (new line) and \t (tabulation)";normalizedString=GlideStringUtil.normalizeWhitespace(mystring);gs.info(normalizedString);

Output:

Text
test with (new line) and (tabulation)

GlideStringUtil - unEscapeHTML(String htmlString)

Replaces escape characters with their respective character.

This method replaces these escape characters: &lt; &gt: &nbsp; &amp; &quote;.

Note: In scoped applications call this method as unescapeHTML(String). In global applications call this method as unEscapeHTML(String).

Name Type Description
htmlString String String to process.
Type Description
String String with the escape characters replaced.

This code example shows the method being called in a global application.

JavaScript
mydata='&quot;&lt;&gt;&amp;';unescaped=GlideStringUtil.unEscapeHTML(mydata);gs.info(unescaped);

Output:

Text
"<>&

This code example shows the method being called in a scoped application.

JavaScript
mydata='&quot;&lt;&gt;&amp;';unescaped=GlideStringUtil.unescapeHTML(mydata);gs.info(unescaped);

Output:

Text
"<>&

GlideStringUtil - urlEncode(String url)

Encodes non-ASCII characters, unsafe ASCII characters, and spaces so you can use the returned string on the Internet. Uses UTF-8 encoding. Uses percent (%) encoding.

Note: Only available in global scope.

Name Type Description
url String String to encode.
Type Description
String String with non-ASCII characters, unsafe ASCII characters, and spaces encoded.
JavaScript
var mystring='Test characters: " < > & &quot; &lt; &gt; &amp;';escapedString=GlideStringUtil.urlEncode(mystring);gs.info(escapedString);

Output:

Text
Test+characters%3A+%22+%3C+%3E+%26+%26quot%3B+%26lt%3B+%26gt%3B+%26amp%3B
Search documentation
Search document titles and file paths on the australia branch