1.1 Section 07 - GlideAjax PDF
1.1 Section 07 - GlideAjax PDF
●
●
●
Client-side
Used to call server-side Script Includes
Similar to jQuery’s ajax method
“ The GlideAjax class
enables a client script to
call server-side code in a
script include.
”
ServiceNow Docs
AJAX
Request 1 Request 1
Request 2
Response 1
Request 2 Response 1
Response 2 Response 2
3 Stages of GlideAjax
1 Client 3
Client-side code calls Client-side code
GlideAjax API, which processes the
makes a XMLHttpRequest response
to server
Server 2
Server-side code
processes the request
and returns a response
2 Scripting Locations To GlideAjax
1 Client-side code 2 Server-side code
Client Server
1 Client makes request for a page that contains a Client Script with GlideAjax
Task form
Update
geolocation on
task
Example: GlideAjax Process
2 Server sends client task form data along with Client Script
3 After an onLoad event occurs, the client side script is executed which calls the GlideAjax API
Task onLoad
event executes
Client Script
Example: GlideAjax Process
GlideAjax
5 Browser’s XMLHttpRequest API sends geolocation data back to ServiceNow in the background
Sends request
Example: GlideAjax Process
Request from client invokes Script Include, where request data is used to call specific methods
6 with arguments. Then data is packaged up in the form of a response.
Sends response
Example: GlideAjax Process
8 Client Script callback processes returned data and updates location field on task
Processes response
and renders data
Show Me The Code!
● Update the short description field of an incident to Hello world! on-load
Dive Deeper: For more information on JavaScript callbacks, checkout this article
JSON Or XML?
Dive Deeper: Checkout this YouTube video for a deeper understanding on XML vs JSON
XML Versus JSON
XML JSON
GlideAjax getXMLAnswer() Method
● Shortcut to
○ getXML()
○ response.responseXML.documentElement.getAttribute(‘answer’)
GlideAjax API Overview
GlideAjax
addParam() getXML()
getXMLAnswer()
GlideAjax Methods
● addParam() ● getXML()
● getXMLAnswer()
Where Can I Use This?
GlideForm GlideRecord
GlideAjax GlideDateTime