Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...


Script include on the client-side

In the example below, we use SimpleAjax on a client-side, and that's what we do:

  1. Create a SimpleAjax instance.
  2. Transfer the called method name using the reserved parameter sysparm_name.
  3. Transfer values from a form using the sysparm_start, sysparm_end, sysparm_schedule parameters.
  4. Call an include script using the getXML(callback) method.
    1. Process its response in the callback-function listed below.
  5. The answer variable will contain value return by the getDuration() method.


Code Block
languagejs
themeEclipse
titleScript include on the client-side
linenumberstrue
if (s_form.getValue('start') &&
  s_form.getValue('end') &&
  s_form.getValue('schedule_id')) {
  const calculate = new SimpleAjax('DurationCalculator'); // call script include
  calculate.addParam('sysparm_name', 'getDuration'); // call method
  calculate.addParam('sysparm_start', s_form.getValue('start')); // pass param
  calculate.addParam('sysparm_end', s_form.getValue('end')); // pass param
  calculate.addParam('sysparm_schedule', s_form.getValue('schedule_id')); // pass param
  calculate.getXML(callback);
  function callback(response) {
    const answer = response.responseXML.documentElement.getAttribute('answer'); // value received from server-side
    s_form.setValue('duration', answer);
  }
}

...