GlideServletRequest - Scoped

The GlideServletRequest API is used in processor scripts.

ServiceNow processors are equivalent to Java servlets. Processors provide a customizable URL endpoint that can execute arbitrary server-side JavaScript code and produce output such as TEXT, JSON, or HTML. The GlideServletRequest API is used in processor scripts to access the HttpServletRequest object. The GlideServletRequest object provides a subset of the HttpServletRequest APIs. The methods are called using the global variable g_request.

A useful global variable, g_target, is available in processor scripts. It contains the table name extracted from the URL.

The URL to a processor has the format: https://<instance name.servicenow.com>/<path endpoint>.do?<parameter endpoint>=<value> where the path endpoint and parameter endpoint are defined on the processor form.

Scoped GlideServletRequest - getContentType()

Returns the MIME type of the body of the request.

Table 1. Parameters
Name Type Description
None
Table 2. Returns
Type Description
String The content type, returns null if the content type is not known.
var contentType = g_request.getContentType();

Scoped GlideServletRequest - getHeader(String name)

Returns the header value.

Table 3. Parameters
Name Type Description
name String The name of the header to be retrieved.
Table 4. Returns
Type Description
String The header.
var headerValue = g_request.getHeader("host");

Output:

demonightlyus.service-now.com

Scoped GlideServletRequest - getHeaderNames()

Returns a comma-separated list of header names.

Table 5. Parameters
Name Type Description
None
Table 6. Returns
Type Description
String A comma-separated list of header names.
var headerList = g_request.getHeaderNames();

Output:

host,connection,cache-control,authorization,accept,user-agent,accept-encoding,accept-language,
cookie,x-forwarded-proto,x-forwarded-host,x-forwarded-for

Scoped GlideServletRequest - getHeaders(String name)

Returns the header values.

Table 7. Parameters
Name Type Description
name String Names of the headers to be retrieved.
Table 8. Returns
Type Description
String The header values.
var headerValue = g_request.getHeaders("host");

Output:

demonightlyus.service-now.com

Scoped GlideServletRequest - getParameter(String name)

Returns the value of the parameter contained in the request URL.

Table 9. Parameters
Name Type Description
name String The name of the parameter to be retrieved. This can be the parameter endpoint from the processor form.
Table 10. Returns
Type Description
Strings The parameter value. Returns null if the parameter is not found.
var name = g_request.getParameter("x_snc_custom_x_snc_name");

Scoped GlideServletRequest - getParameterNames()

Returns a list of the parameter names found in the request URL.

Table 11. Parameters
Name Type Description
None
Table 12. Returns
Type Description
String A comma-separated list of parameter names.
var paramList = g_request.getParameterNames();

Scoped GlideServletRequest - getQueryString()

Returns the query string from the request.

Table 13. Parameters
Name Type Description
None
Table 14. Returns
Type Description
String The query string.

The code snippet is:

var daString = g_request.getQueryString();
g_processor.writeOutput("The query string is: " + daString);
Output: The request URL is: https://demonightlycloudedge.service-now.com/x_custom_app_customApp.do?x_custom_app_name=George&bell=rung
The query string is: x_custom_app_name=George&bell=rung