Identifying and reducing synchronous AJAX calls generated by client scripts
- 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 time for 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.|
|Release: GlideAjax replaced the AjaxEvaluate functionality in the Fall 2009 Stable 2 release.|
|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.|
- Use of GlideRecord invocations in onLoad and onChange client scripts.
- Use of getReference invocations in onLoad and onChange client scripts.
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 with the 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.
- In the debugger window, click the Clear link.
- Click the link for the form.
Note: These messages contain the following text: *** WARNING *** GlideRecord sync query for table: <table_name>
- The client script that issued the synchronous request is identified in a debug message immediately following the warning message.
Note: These messages use the following format: onLoad <client_script_name>
To resolve this issue by consolidating requests:
- Refactor and combine existing client scripts that make redundant requests for the same data.
- Make the call for the data at the top of a single script.
- In the newly combined client script, rewrite previously separate client scripts as functions that can be called after the data is retrieved.
To resolve this issue by utilizing the GlideAjax API:
- The GlideAjax API allows for asynchronous calls for data and server-side script processing, which will not pause interaction with the form.
- In situations when it is okay for the user to begin interacting with the form prior to client script completion, GlideRecord and getReference() invocations can be replaced with GlideAjax equivalents.
|Note: For more information on using GlideAjax, refer to GlideAjax in the ServiceNow product documentation.|
- Refactor eligible client scripts to use GlideAjax.
If the issue continues to exist after following the steps in this article:
- Clearly identify the issue or question.
- Read the ServiceNow product documentation.
- Search the ServiceNow Community.
- Post a question on the ServiceNow Community forums. New users must create an account on the ServiceNow Community in order to post.
- Contact the Technical Support team.
|For more information on how to submit an incident, see Customer Support.|
For more information on related topics, review the following product documentation pages:
- Performance Troubleshooting Guide
- Performance Metrics
- Thread Performance Monitoring
- System Diagnostics
For more topic related issues, review the following Knowledge Base article: