This class allows the client script executing the code on the server side using Script Includes.
To use SimpleAjax class, please complete the following steps:
Create a SimpleAjax instance, for this you have to call SimpleAjax constructor. The script include name involving the class containing the necessary methods should be the argument for the constructor.
Call the addParam(paramName, paramValue) method with sysparm_name parameter and method name from include part of the script you want to call. To provide other parameters to the script code, call this method as many times as how many parameters are to be transferred.
Сall the getXML(callback) method to execute method declared above.
The class name declared in the script include should match the script include name.
To make the script include callable from client-side scripts, please activate the Client Callable attribute.
For more information and practical cases, please refer to the Script Includes article.
addParam(paramName, paramValue)
This method specifies the parameter name and its value to be passed to the server-side function, associated with current SimpleAjax object. You can run the addParam() method more than once with different parameters and values.
The server-side code does not execute until client script will not call getXML(). Parameter name should start with sysparm_ prefix. Avoid using a predefined sysparm_name parameter name for passing value parameters.
Parameter(s):
Name
Type
Mandatory
Default value
paramName
String
Y
N
paramValue
String
Y
N
Return:
Type
Description
Void
This method does not return a value
Example:
addParam
const calculate = new SimpleAjax('DurationCalculator'); // call script include
calculate.addParam('sysparm_name', 'getDuration'); // call class method
calculate.addParam('sysparm_start', s_form.getValue('start')); // pass parameter
getXML(callback)
This method sends the request to the server to execute a method and parameters related to current SimpleAjax object. The server processes the request asynchronously. The results will be returned via the function specified as a callback.
Return:
Type
Description
Void
This method does not return a value.
Example:
getXML
const calculate = new SimpleAjax('DurationCalculator'); // call script include
calculate.addParam('sysparm_name', 'getDuration'); // call class method
calculate.addParam('sysparm_start', s_form.getValue('start')); // pass parameter
calculate.addParam('sysparm_end', s_form.getValue('end'));
calculate.addParam('sysparm_schedule', s_form.getValue('schedule_id'));
calculate.getXML(callback);
runScript(scriptValue, tableName)
This method allows to run a script against a table specified.