JSUtil - Global
-
- UpdatedFeb 1, 2024
- 6 minutes to read
- Washington DC
- API reference
The JSUtil API provides shortcuts for common JavaScript routines.
This API is available in global server-side scripts, not scoped scripts.
JSUtil - doesNotHave(Object item)
Checks if item is null or is undefined.
Name | Type | Description |
---|---|---|
item | Object | The object to check |
Type | Description |
---|---|
Boolean | True if the specified object is null or undefined. |
Example
JSUtil - escapeAttr(String text)
Escape ampersands commonly used to define URL attributes.
Name | Type | Description |
---|---|---|
text | String | The text |
Type | Description |
---|---|
String | The text with ampersands properly escaped. |
Example
JSUtil - escapeText(String text)
Escapes invalid XML characters such as "< > &".
Name | Type | Description |
---|---|---|
text | String | The text |
Type | Description |
---|---|
String | The text with escape characters added. |
Example
JSUtil - getBooleanValue(GlideRecord now_GR, String field)
Returns the value in a boolean GlideRecord field.
Name | Type | Description |
---|---|---|
now_GR | GlideRecord | A GlideRecord |
field | String | The field from which to retrieve the boolean value. |
Type | Description |
---|---|
Boolean | Returns the value in a boolean GlideRecord field, returns true if value of field is true, "true", 1, or "1". |
Example
Output: true
JSUtil - has(Object item)
Checks if item is not null and is not undefined.
Name | Type | Description |
---|---|---|
item | Object | The Object to check |
Type | Description |
---|---|
Boolean | True if the specified object is not null and is not undefined. |
Example
JSUtil - instance_of(Object item, String class)
Checks to see if the specified object is a member of the specified class.
For JavaScript objects, this method behaves exactly like the JavaScript operator "instanceof", but also supports Java objects.
Name | Type | Description |
---|---|---|
item | Object | The object to check |
class | String | The class to check |
Type | Description |
---|---|
Boolean | True if the specified object is a member of the specified class. |
Example
JSUtil - isJavaObject(Object value)
Checks if the specified object is a Java class.
Name | Type | Description |
---|---|---|
value | Object | The object to check |
Type | Description |
---|---|
Boolean | True if the specified object is an instance of a Java class. |
Example
JSUtil - logObject(Object obj, String name)
Logs all the properties in the given object: name, type, and value.
Output is written to the console if you are running from a background script or have debug logging enables. The output is also written to the system log.
Name | Type | Description |
---|---|---|
obj | Object | The object for which to enumerate properties |
name | String | Optional name for the logged object |
Type | Description |
---|---|
void |
Example
JSUtil - nil(Object item)
Checks if item is null, undefined, or evaluates to the empty string.
Name | Type | Description |
---|---|---|
item | Object | The object to check |
Type | Description |
---|---|
Boolean | True if the item is null, undefined, or evaluates to the empty string. |
Example
JSUtil - notNil(Object item)
Checks if an item is null, undefined, or evaluates to the empty string.
Name | Type | Description |
---|---|---|
item | Object | The object to check. |
Type | Description |
---|---|
Boolean | Flag that indicates whether the item exists and isn’t empty. An error returns if the object provided isn’t declared. Valid values:
|
Example
The following example shows results for a string variable, an empty string variable, and an undefined variable.
JSUtil - toBoolean(Object item)
Converts the specified object to a Boolean.
Name | Type | Description |
---|---|---|
item | Object | The object to convert |
Type | Description |
---|---|
Boolean | If the specified object is a boolean, it is passed through. Non-zero numbers return true. Null or undefined return false. Strings return true only if exactly equal to 'true'. |
Example
JSUtil - type_of(Object value)
Determines the type of the specified object.
Name | Type | Description |
---|---|---|
value | Object | The object to check |
Type | Description |
---|---|
String | The type of the specified object.
|
Example
JSUtil - unescapeAttr(String text)
Restore ampersands from escaped text.
Name | Type | Description |
---|---|---|
text | String | The text |
Type | Description |
---|---|
String | The text with escape characters removed. |
Example
JSUtil - unescapeText(String text)
Removes escape characters.
Name | Type | Description |
---|---|---|
text | String | The text to process. |
Type | Description |
---|---|
String | The the text without escape characters. |
Example
On this page
- JSUtil - doesNotHave(Object item)
- JSUtil - escapeAttr(String text)
- JSUtil - escapeText(String text)
- JSUtil - getBooleanValue(GlideRecord now_GR, String field)
- JSUtil - has(Object item)
- JSUtil - instance_of(Object item, String class)
- JSUtil - isJavaObject(Object value)
- JSUtil - logObject(Object obj, String name)
- JSUtil - nil(Object item)
- JSUtil - notNil(Object item)
- JSUtil - toBoolean(Object item)
- JSUtil - type_of(Object value)
- JSUtil - unescapeAttr(String text)
- JSUtil - unescapeText(String text)