Description

Loading a form, such as an incident, takes too long or freezes before any interaction is possible.

The Client Transaction Timing widget or log indicates a high amount of browser timefor a particular form transaction.

Release: Available since October2011 Preview 1, a multi-line field was added to client scripts. Strings entered here (one per line) are made available to the client script as localized messages without the need for an AJAX call, using getMessage(msg) syntax.

Note: To call a business rule from a client script, use GlideAjax. The GlideAjax class allows the execution of server-side code from the client.

Cause

Use of GlideRecord invocations in onLoad and onChange client scripts.

Use of getReference invocations in onLoad and onChange client scripts.

Resolution

Client scripts add functionality to the forms user interface and can retrieve data from the server to populate fields or inform logic that affects the user's interactivity with the form. While there is a variety of methods for retrieving data from the server after the initial page request, some of these methods employ synchronous retrieval. This pauses the interactivity with the browser window until the data is retrieved and the script is executed. Making multiple round-trip requests for data after a form has loaded can pause a form for an extended period of time.

To identify synchronous AJAX calls that occur when loading a form:

Important: A browser with debugging capability is required for this sequence. Firefox comes with an add-on called Firebug, which is used in the following documented steps. Other browsers such as Chrome, Safari, and recent versions of Internet Explorer have similar utilities.

In the ServiceNow instance, locate the record link for the slow form.

Turn on the Firebug add-on and enable the following settings:

Enable the Net panel.

As the content type, select XHR.

Click the Clear button, then click the link to the form.

In the Firebug frame, observe whether any entries appear with URL values of POST xmlhttp.do.

Expand each xmlhttp.do request and examine the data listed in the Post tab for each request.

Note: Synchronous AJAX requests can be identified as having a sysparm_processor value of AJAXGlideRecord.

In the Post tab, record the sysparm_chars and sysparm_name values for each synchronous AJAX request.

Important: If multiple requests have identical values for both parameters, then redundant requests for the same data are being issued and can be consolidated.

From the Timeline column, record the combined timing for all synchronous AJAX requests with a sysparm_processor value of AJAXGlideRecord.

Note: Converting these requests to async withthe GlideAjax Application Programming Interface (API) can potentially reduce the time spent on the form load.

To identify the client script that issues a synchronous AJAX call:

Prepare a record link for the slow form.

Click the JavaScript Debugger Window icon, which is the green bug located at the top right corner of the main frame.