- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2016 03:45 PM
Hi Steve,
You might find this useful:
---------------------------------
Calculating a duration and setting that value using a client script
Here's an example of how to use the 'gs.dateDiff' function to return a value and populate it using a client script.
--Create an 'onChange' client script that includes the following code. You can modify this script if you need the calculation to happen in an 'onLoad' script or some other way.
function onChange(control, oldValue, newValue, isLoading) {
var strt = g_form.getValue('<start_field>');
var end = g_form.getValue('<end_field>');
var ajax = new GlideAjax('AjaxDurCalc');
ajax.addParam('sysparm_name','durCalc');
ajax.addParam('sysparm_strt',strt);
ajax.addParam('sysparm_end',end);
ajax.getXMLWait();
var answer = ajax.getAnswer();
g_form.setValue('<duration_field>', answer);
}
--Create a system script include file called AjaxDurCalc that handles the request. It may be reused for other functions as well.
var AjaxDurCalc = Class.create();
AjaxDurCalc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
durCalc: function() {
return gs.dateDiff(this.getParameter('sysparm_strt'),this.getParameter('sysparm_end'), false);
}
});