You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 41 Next »

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.

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.

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:

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
calculate.addParam('sysparm_end', s_form.getValue('end'));
calculate.addParam('sysparm_schedule', s_form.getValue('schedule_id'));
calculate.getXML(callback);

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:

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, callback)


This method allows to run a script against a table specified.

The callback function receives the answer element of the response.

Parameter(s):

NameTypeMandatoryDefault Value
scriptValueStringYN
tableNameStringYN
callbackFunctionNN

Return:

TypeDescription
VoidThis method does not return a value.

Example:

runScript
const sAjax = new SimpleAjax();
const scriptValue =
  `const task = new SimpleRecord('task');
  task.get('${s_form.getUniqueValue()}');
  const creationDateTime = new SimpleDateTime().getDisplayValue();
  task.description +=
    '\\n\\n' + \`\${creationDateTime} \\u00b7\` + ' ${s_user.getFullName()}: ' + '"${s_form.getValue('comment')}"';
  task.update();`;
sAjax.runScript(scriptValue, 'task', s_go.reloadWindow());

  • No labels