GlideServletResponse - Scoped

The GlideServletResponse 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 GlideServletResponse API is used in processor scripts to access the HttpServletResponse object. The GlideServletResponse object provides a subset of the HttpServletResponse APIs. The methods are called using the global variable g_response.

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 GlideServletResponse - setContentType(String type)

Sets the MIME type of the response

Table 1. Parameters
Name Type Description
type String The MIME type.
Table 2. Returns
Type Description
void
g_response.setContentType('text/html;charset=UTF-8');

Scoped GlideServletResponse - setHeader(String key, String value)

Sets a response header to the specified value.

Table 3. Parameters
Name Type Description
key String Specifies the header.
value String The value to be assigned to the header. If the header exists, it is over written.
Table 4. Returns
Type Description
void
g_response.setHeader("host", "demonightlyus.service-now.com");

Scoped GlideServletResponse - setStatus(Number status)

Sets the status code for the response.

Table 5. Parameters
Name Type Description
status Number The status to be set.
Table 6. Returns
Type Description
void
// set the status to okay
g_response.setStatus(200);

Output:

Scoped GlideServletResponse - sendRedirect(String location)

Sends a temporary redirect to the client.

Table 7. Parameters
Name Type Description
location String The URL to receive the response.
Table 8. Returns
Type Description
void