Script includes used to store JavaScript functions and classes that will execute on the server. Script includes specify either object class or function.
Role required: admin. |
A script include has a name, a description, and a script itself. Also, it is possible to specify if it is active or client-callable.
To create a new script include, please complete the following steps:
Field | Description | ||
---|---|---|---|
Name | Script include name | ||
Description | Short action description | ||
Active | When set to TRUE, this script will execute when called; otherwise, it will not execute. | ||
Client callable | When set to TRUE, this script will be available to call on the client-side scripts. | ||
Script | Define the server-side script to run when called from other scripts
|
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.
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; } }); |
Script include on the client-side
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'); calculate.addParam('sysparm_start', s_form.getValue('start')); calculate.addParam('sysparm_end', s_form.getValue('end')); calculate.addParam('sysparm_schedule', s_form.getValue('schedule_id')); calculate.getXML(callback); function callback(response) {const answer = response.responseXML.documentElement.getAttribute('answer'); s_form.setValue('duration', answer); } } |