...
Script include on the client-side
In the example below, we use SimpleAjax on a client-side, and that's what we do:
- Create a SimpleAjax instance.
- Transfer the called method name using the reserved parameter sysparm_name.
- Transfer values from a form using the sysparm_start, sysparm_end, sysparm_schedule parameters.
- Call an include script using the getXML(callback) method.
- Process its response in the callback-function listed below.
- The answer variable will contain value return by the getDuration() method.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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); } } |
...