Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Merged branch "DOC0000508: Актуализация и новая дока для SimpleAjax" into parent

This class allows the client-side script executing the code on the server side using Script Includes.

To use SimpleAjax class, please complete the following steps:

  1. Call the SimpleAjax constuctor to create a SimpleAjax instance. The script include name, which involves the class with the necessary methods, should be the argument for the constructor.
  2. Call the addParam(paramName, paramValue) method. When calling it, provide sysparm_name as a parameter and the method name taken from the include part of the script called. To provide other parameters to the script code, call this method as many times as you need.
  3. Сall the getXML(callback) method to execute method declared above.
Note

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 passes 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 runs only after getXML() is called by client script.

Parameter name should start with sysparm_ prefix. Avoid using a predefined sysparm_name parameter name for passing value parameters.


Parameter(s):

NameTypeMandatoryDefault value
paramNameStringYN
paramValueStringYN


Return:

TypeDescription
VoidThis method does not return a value


Example:

Code Block
languagejs
themeEclipse
titleaddParam
linenumberstrue
<![CDATA[const calculatesAjax = new SimpleAjax('DurationCalculator'); // call script include
calculatesAjax.addParam('sysparm_name', 'getDuration'); // call class method
calculatesAjax.addParam('sysparm_start', s_form.getValue('start')); // pass parameter
calculatesAjax.addParam('sysparm_end', s_form.getValue('end'));
calculate.addParam('sysparm_schedule', s_form.getValue('schedule_id'));
calculate.getXML(callback);getXML(callback);

function callback(response) {
  const answer = response.responseXML.documentElement.getAttribute('answer');
  console.log(answer);
}

getXML(callback)


By calling this method, the client script sends a request to the server where the method and parameters related to the current SimpleAjax object are executed. The request is processed asynchronously. The results will be returned via the function specified as a callback. 


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlegetXML
linenumberstrue
<![CDATA[const calculatesAjax = new SimpleAjax('DurationCalculator'); // call script include
calculatesAjax.addParam('sysparm_name', 'getDuration'); // call class method
calculatesAjax.addParam('sysparm_start', s_form.getValue('start')); // pass parameter
calculatesAjax.addParam('sysparm_end', s_form.getValue('end'));
calculate.addParam('sysparm_schedule', s_form.getValue('schedule_id'));
calculate.getXML(callback);getXML(callback);

function callback(response) {
  const answer = response.responseXML.documentElement.getAttribute('answer');
  console.log(answer);
}


runScript(scriptValue, tableName, callback)


This method allows to run a script against a table specified. The script is run with the <![CDATA[ ACL restrictions.

Info

The callback function receives the answer element of the response.


Parameter(s):

NameTypeMandatoryDefault Value
scriptValueStringYN

tableName

Tooltip
onlyIcontrue
appendIconinfo-filled
iconColorblue

This parameter is used for displaying information and the script run result on some pages, such as record/sys_script.


StringNN
callbackFunctionNN

Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlerunScript
linenumberstrue
<![CDATA[const CURRENT_ID = s_form.getUniqueValue();

const simpleAjax = new SimpleAjax();
await simpleAjax.runScript(
  `const current = `const supportSiteURL = ss.getProperty('simple.auth_page.support_sitenew SimpleRecord('task');
  current.get('${CURRENT_ID}');
    print(supportSiteURLsetResult(current.caller.email)`,
    null,
    (response) => {
        const serverData = console.log(response.data.inforesult);
        console.log(serverData);
    })
Example 2
}
)


runAdminScript(scriptValue, tableName, callback)


This method allows to run a script by a user with the administrator role. The script is run without the ACL restrictions. If the user who does not have the administrator role attempts to a run a script, the script will not be run, and the method will return an empty result. Therefore, 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):

NameTypeMandatoryDefault Value
scriptValueStringYN

tableName

Tooltip
onlyIcontrue
appendIconinfo-filled
iconColorblue

This parameter is used for displaying information and the script run result on some pages, such as record/sys_script.


StringNN
callbackFunctionNN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlerunScript
linenumberstrue
const CURRENT_ID = s_form.getUniqueValue();

<![CDATA[const simpleAjax = new SimpleAjax();
await simpleAjax.runScriptrunAdminScript(
    `const currentsupportSiteURL = new SimpleRecord('task');
  current.get('${CURRENT_ID}ss.getProperty('simple.auth_page.support_site');
  print(current.caller.emailsetResult(supportSiteURL)`,
    null,
    (response) => {
    const serverData = response.data.result;
    console.log(response.data.infoserverData);
    }
)


Table of Contents
absoluteUrltrue
classfixedPosition