Versions Compared

Key

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

...

You can call a server-side script include in case if you need to use server-side methods on the client-side. To perform this, activate the Client Callable attribute.

Code Block
languagejs
themeEclipse
titleServer-side script include on the client-side
linenumberstrue
ss.importIncludeScript('AbstractAjaxProcessor');
var DurationCalculator = Class.create();
DurationCalculator.prototype = Object.extendsObject(AbstractAjaxProcessor, {
  getDuration() {
    const start = new SimpleDateTime(this.getParameter('sysparm_start'));
    const end = new SimpleDateTime(this.getParameter('sysparm_end'));
    const scheduleID = this.getParameter('sysparm_schedule');
    const schedule = new SimpleSchedule(scheduleID);
    return schedule.duration(start, end).getDurationSeconds() * 1000; // value that would be passed to client-side
  }
});


Script include on the client-side

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 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);
  }
}

...