- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2014 07:36 AM
Looking for a GlideAJAX API (ie; getXML, addParam, etc). Can someone point me in the right direction ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2014 08:56 AM
The wiki article is the most comprehensive document that I am aware of on GlideAjax. GlideAjax lets you run server side scripts from the client. The GlideAjax client side object and the AbstractAjaxProcessor script include negotiate the XML request and response. So the communication looks like this:
Request: Your Client Script => GlideAjax => AbstractAjaxProcessor => Your Script Include
Response: Your Script Include => AbstractAjaxProcessor => GlideAjax => Your Client Script
1. Your client script creates a GlideAjax object and sets parameters in the request XML.
2. Your client script calls getXML (async, client can run other scripts while waiting for a response)
3. AbstractAjaxProcessor (which is inherited by your script include) processes the request message and hands it off to your Script Include
4. Your script include uses getParameter to read the request, processes the request and uses setAttribute to generate a response.
5. AbstractAjaxProcessor responds to the client with the XML message generated transparently in step 4
6. GlideAjax notifies your Client Script that the response has been received by calling the async function that you passed into the first parameter of the GlideAjax.getXML function
So now lets look at the objects:
Glide Ajax
- GlideAjax(scriptIncludeName): The GlideAjax constructor takes the name of a Script Include as its only parameter. This is the Script Include that GlideAjax will use to process the AJAX request.
- addParam(name, value): Adds parameters to the XML request which can be consumed by the Script Include's getParamter function. It accepts two parameters, name and value. Name is a string you will use in the getParamter function to retrieve the value set in the Value parameter.
- getXML(ajaxResponse): Sends the XML asynchronously, allowing the client to continue processing. The ajaxResponse parameter should be a function that accepts a single parameter which will contain the response message. The ajaxResponse function will be called when GlideAjax receives the response from the server.
AbstractAjaxProcessor
The AbstractAjaxProcessor should be inherited by the Script Include used in the GlideAjax constructor. AbstractAjaxProcessor function calls can then be made within the Script Include by prefixing with the 'this' keyword.
Example:
this.getParameter('name');
- getParameter(paramName): Returns the value for a parameter with the name passed into the paramName (as created by GlideAjax's addParam function).
- newItem(elemName): Creates a new element in the XML response. The element will have the name given in the elemName parameter. Example: this.newItem('hello'); creates an XML element <hello></hello>. The function returns the XML element object.
XML Element
XML elements are created by the AbstractAjaxProcessor newItem function call.
Example:
var result = this.newItem('result'); // result is an XML Element object <result></result>
- setAttribute(name, value): Creates an attribute on the XML Element with the name and value parameters. Example:
result.setAttribute('hello', 'world'); // From the previous example will create <result hello="world"></result>
Ajax Response Object
Ajax response object is passed into the ajaxResponse function passed to GlideAjax's getXML function. The XML can then be accessed via serverResponse.responseXML.
Example (assume ga is a GlideAjax variable):
ga.getXML(ajaxRepsonse);
function ajaxResponse(serverResponse) {
var answer = serverResponse.responseXML; // answer contains the XML response object created in the Script Include
}
- getElementsByTagName(elemName): Gets a client side element object. The elemName refers to the element name created in the Script Include via the AbstractAjaxProcessor's newItem function. Returns an array of element objects. Example:
var result = responseXML.getElementsByTagName("result"); // Returns an array of elements. The <result hello="world"></result> created in the example above would be returned in an array of 1 item in this case.
Client Side XML Element
- getAttribute(name): Returns the value for an attribute as set by the Script Include using the setAttribute function. Example:
// Continuing from previous example
var i,
hello;
for (i = 0; i < result.length; i++) {
hello = answer.getAttribute("hello"); // Returns the string 'world' as set in the setAttribute example
}
Apart from implementation, that is about all there is to GlideAjax. Of course, I focused only on async but this is the preferred method of handling GlideAjax. Please let us know if you have more specific questions about the API. I hope this helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2017 05:22 AM
This is now a dead link.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-13-2014 08:56 AM
The wiki article is the most comprehensive document that I am aware of on GlideAjax. GlideAjax lets you run server side scripts from the client. The GlideAjax client side object and the AbstractAjaxProcessor script include negotiate the XML request and response. So the communication looks like this:
Request: Your Client Script => GlideAjax => AbstractAjaxProcessor => Your Script Include
Response: Your Script Include => AbstractAjaxProcessor => GlideAjax => Your Client Script
1. Your client script creates a GlideAjax object and sets parameters in the request XML.
2. Your client script calls getXML (async, client can run other scripts while waiting for a response)
3. AbstractAjaxProcessor (which is inherited by your script include) processes the request message and hands it off to your Script Include
4. Your script include uses getParameter to read the request, processes the request and uses setAttribute to generate a response.
5. AbstractAjaxProcessor responds to the client with the XML message generated transparently in step 4
6. GlideAjax notifies your Client Script that the response has been received by calling the async function that you passed into the first parameter of the GlideAjax.getXML function
So now lets look at the objects:
Glide Ajax
- GlideAjax(scriptIncludeName): The GlideAjax constructor takes the name of a Script Include as its only parameter. This is the Script Include that GlideAjax will use to process the AJAX request.
- addParam(name, value): Adds parameters to the XML request which can be consumed by the Script Include's getParamter function. It accepts two parameters, name and value. Name is a string you will use in the getParamter function to retrieve the value set in the Value parameter.
- getXML(ajaxResponse): Sends the XML asynchronously, allowing the client to continue processing. The ajaxResponse parameter should be a function that accepts a single parameter which will contain the response message. The ajaxResponse function will be called when GlideAjax receives the response from the server.
AbstractAjaxProcessor
The AbstractAjaxProcessor should be inherited by the Script Include used in the GlideAjax constructor. AbstractAjaxProcessor function calls can then be made within the Script Include by prefixing with the 'this' keyword.
Example:
this.getParameter('name');
- getParameter(paramName): Returns the value for a parameter with the name passed into the paramName (as created by GlideAjax's addParam function).
- newItem(elemName): Creates a new element in the XML response. The element will have the name given in the elemName parameter. Example: this.newItem('hello'); creates an XML element <hello></hello>. The function returns the XML element object.
XML Element
XML elements are created by the AbstractAjaxProcessor newItem function call.
Example:
var result = this.newItem('result'); // result is an XML Element object <result></result>
- setAttribute(name, value): Creates an attribute on the XML Element with the name and value parameters. Example:
result.setAttribute('hello', 'world'); // From the previous example will create <result hello="world"></result>
Ajax Response Object
Ajax response object is passed into the ajaxResponse function passed to GlideAjax's getXML function. The XML can then be accessed via serverResponse.responseXML.
Example (assume ga is a GlideAjax variable):
ga.getXML(ajaxRepsonse);
function ajaxResponse(serverResponse) {
var answer = serverResponse.responseXML; // answer contains the XML response object created in the Script Include
}
- getElementsByTagName(elemName): Gets a client side element object. The elemName refers to the element name created in the Script Include via the AbstractAjaxProcessor's newItem function. Returns an array of element objects. Example:
var result = responseXML.getElementsByTagName("result"); // Returns an array of elements. The <result hello="world"></result> created in the example above would be returned in an array of 1 item in this case.
Client Side XML Element
- getAttribute(name): Returns the value for an attribute as set by the Script Include using the setAttribute function. Example:
// Continuing from previous example
var i,
hello;
for (i = 0; i < result.length; i++) {
hello = answer.getAttribute("hello"); // Returns the string 'world' as set in the setAttribute example
}
Apart from implementation, that is about all there is to GlideAjax. Of course, I focused only on async but this is the preferred method of handling GlideAjax. Please let us know if you have more specific questions about the API. I hope this helped.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2016 10:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-20-2020 12:11 AM
Check out this video, it will clear all your doubts and help you to understand Script Include And Ajax Call queries in details.
Link: https://www.youtube.com/watch?v=qNiYWMMzC2o&t=209s&ab_channel=ServiceNowHelpdesk
It help you to understand below points.
- Understand Script Include And Ajax Call
- When, How and in which scenario we will use it.
- Understand Synchronous (getXMLWait()) and aSysnchronous (getXML()) Ajax call and scenario based use of it.
Please mark reply as Helpful/Correct, if applicable. Thanks!!