Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
This class allows the client-side script executing the code provides methods that allow the client-side script to be executed on the server side using Script IncludesInclude.
To use the SimpleAjax class, complete the following steps:
- Call the SimpleAjax constructor to create a SimpleAjax instance. The script includes a name, which An argument for the constructor should be the name of the script include that involves the class with the necessary methods, should be the argument for the constructor.
Call the addParam(paramName, paramValue) method. Pass the required parameters defining the method
. When calling it, provideneeded as the main call. To do so, complete the following steps:
- set the sysparm_name
- parameter.
- and the method name taken from the
- defined class called by the script
- include.
To provide other parameters to the script
codeinclude, call this method as many times as you need.
- Сall the Call the getXML(callback) method to execute the method declared above.
Note |
---|
The class name declared in the script include Script Include record should match the script include name. To make the a script include callable include callable from the client-side scripts, please activate the Client Callablecallable attribute. For more information and practical cases, please refer to the Script Includes articleSee the Script Include article to learn more. |
addParam( paramName, paramValue)
This Use this method passes to pass the specified parameter name and value to the server-side function associated with the current SimpleAjax object. The addParam() method can be used several times with different parameters and values.
Note |
---|
The server-side code script only runs only after after getXML() is called by the client script. Parameter The parameter name should start with the sysparm_ prefix. Avoid using a predefined sysparm_name parameter name for passing value parametersfor passing the value to the function parameter. |
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:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const sAjax = new SimpleAjax('DurationCalculator'); // call script include sAjax.addParam('sysparm_name', 'getDuration'); // call class method sAjax.addParam('sysparm_start', s_form.getValue('start')); // pass parameter sAjax.getXML(callback); function callback(response) { const answer = response.responseXML.documentElement.getAttribute('answer'); console.log(answer); } |
getXML(callback)
Anchor | ||||
---|---|---|---|---|
|
By calling this method, the client script sends a request to the server, where the method and parameters related related to the current SimpleAjax object are is executed with the specified parameters. The request is processed asynchronouslyprocessed asynchronously. The results The results of the server-side method execution will be returned via passed to the function specified as a callback function.
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const sAjax = new SimpleAjax('DurationCalculator'); // call script include sAjax.addParam('sysparm_name', 'getDuration'); // call class method sAjax.addParam('sysparm_start', s_form.getValue('start')); // pass parameter sAjax.getXML(callback); function callback(response) { const answer = response.responseXML.documentElement.getAttribute('answer'); console.log(answer); } |
runScript(scriptValue, tableName, callback)
This Use this method allows to run a script against a table specified. The script is run runs with the ACL restrictions.
Info |
---|
The callback function receives the answer element of the response. |
Parameter(s)Parameters:
Name | Type | Mandatory | Default Valuevalue | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
scriptValue | String | Y | N | |||||||||
tableName
| String | N | N | |||||||||
callback | Function | N | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const CURRENT_ID = s_form.getUniqueValue(); const simpleAjax = new SimpleAjax(); await simpleAjax.runScript( `const current = new SimpleRecord('task'); current.get('${CURRENT_ID}'); setResult(current.caller.email)`, null, (response) => { console.log(response.data.result); } ) |
runAdminScript(scriptValue, tableName, callback)
This Use this method allows to run a script by a user with the . To do so, an administrator role. The script is run without the ACL restrictions. If the user who is necessary. There are no ACL restrictions for the script. If a user that does not have the administrator role, attempts to a run a script, the script will not be run, and the method will return returns an empty result as callback. Therefore, before Before using the script result, verify that the response.data.result
is not empty.
Info |
---|
The callback function receives the answer element of the response. |
Parameter(s)Parameters:
Name | Type | Mandatory | Default Valuevalue | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
scriptValue | String | Y | N | |||||||||
tableName
| String | N | N | |||||||||
callback | Function | N | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const simpleAjax = new SimpleAjax(); await simpleAjax.runAdminScript( `const supportSiteURL = ss.getProperty('simple.auth_page.support_site'); setResult(supportSiteURL)`, null, (response) => { const serverData = response.data.result; console.log(serverData); } ) |
Table of Contents | ||||
---|---|---|---|---|
|