what is glide ajax syntax?

rajasekharyasam
Kilo Contributor

werty

6 REPLIES 6

Bharath40
Giga Guru

Hi



If you want to do any validations on server side, you will have to use GlideAjax from a client script and pass the information to a script include and perform the server side validations and return a value to the client side


GlideAjax - ServiceNow Wiki


_onali
Kilo Contributor

Hi rajasekhar,


Asynchronous Glide Ajax

var ga = new GlideAjax('className');


ga.addParam('sysparm_name','myfunction_name');


ga.addParam('sysparm_user_name',"parameter1");


ga.getXML(HelloWorldParse);



A callback function :



function HelloWorldParse(response) {


    var answer = response.responseXML.documentElement.getAttribute("answer");


    alert(answer);


}



For more details please visit


GlideAjax - ServiceNow Wiki


PriyaRanji
Tera Guru

Hi Raja,



Good Day



Please find the below brief information about the GlideAjax for your reference.



GLIDEAJAX :


The GlideAjax class is used by client-side scripts to send data to and receive data from the ServiceNow server. The client-side script passes parameters to the Script Include. The Script Include returns data as XML or a JSON object. The client-side script parses data from the response and can use the data in subsequent script logic.


find_real_file.png


Script Include for Retrieving an Email Address

The Script Include must be client callable because it will be used by client-side scripts.


    find_real_file.png


The AbstractAjaxProcessor class is part of the Global Scope. The GetEmailAddress Script Include is in the NeedIt scope. To extend the AbstractAjaxProcessor, the class must be prepended by the scope: global.AbstractAjaxProcessor. The new class defines a method called getEmail.


find_real_file.png



The syntax this.getParameter('sysparm_<parameter_name>') means to get the value of the parameter passed in from the client-side script. In this example, sysparm_userID contains the sys_id of a User table record.



Client-side Script for Using the GetEmailAddress Script Include


Any in-scope client-side script can use Script Includes which extend the AbstractAjax Processor. The generalized syntax is:


find_real_file.png



The first call to addParam() should be for the parameter sysparm_name and should pass as the value the name of the server-side method you want to call. Use addParam to pass user-defined parameters starting with sysparm_ and their values. Users can create their own sysparm_ variables except sysparm_name, sysparm_type, sysparm_function and sysparm_value.



The getXML method sends the server a request to execute the method and parameters associated with this GlideAjax object. The server processes the request asynchronously and returns the results via the function specified as the callback function. This example, which uses a callback function, is asynchronous meaning that the user's screen is not frozen while the script waits for a response to come back from the server. Asynchronous GlideAjax is recommended over synchronous.


The callback function is passed the response back from the server. The script logic extracts the return value from the response. Subsequent script logic can use the extracted value.


Here is the client-side logic for using the GetEmailAddress Script Include:


find_real_file.png


Please mark it as correct/helpful/like based on the impact if the response.


Thanks,


Priyanka R