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

Compare with Current View Page History

« Previous Version 39 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:

  • 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):

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)


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:

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
callbackFunctionYN

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