Find difference between two dates in minutes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2016 06:17 AM
I have two fields ( Glide date time) , called outage stat and outage end.
i have another field called Total Outage (in minutes). This should be auto calculated based off the Outage Start and Outage End fields.
This is what I've done so far ; but doesn't work.
As this a n onchange client script, which field should i select as the change field?( start I guess?)
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var strt = g_form.getValue('u_outage_start');
var end = g_form.getValue('u_outage_end');
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('u_total_outage_in_minutes', answer);
}
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2016 06:28 AM
How does the script include look like? What happens if you put the answer in a alert. what value are you getting back?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2016 06:41 AM
this is the script include
var AjaxDurCalc = Class.create();
AjaxDurCalc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
durCalc: function() {
return gs.dateDiff(this.getParameter('sysparm_strt'),this.getParameter('sysparm_end'), false);
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2016 06:46 AM
The alert brings null
I'm not sure which field i should set as the change field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2016 07:24 AM
Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var strt = g_form.getValue('start_date');
var end = g_form.getValue('end_date');
var ajax = new GlideAjax('counttime');
ajax.addParam('sysparm_name','calcutime');
ajax.addParam('sysparm_strt',strt);
ajax.addParam('sysparm_end',end);
ajax.getXMLWait();
g_form.setValue('u_total_outage_in_minutes', answer);
}
Script include:
var counttime = Class.create();
counttime.prototype = Object.extendsObject(AbstractAjaxProcessor, {
calcutime: function() {
var start= this.getParameter('sysparm_strt');
var end = this.getParameter('sysparm_end');
result = gs.dateDiff(start, end, true);
result = result/60;//Reslut in seconds, so divided with 60 to get minutes
return result;
},
type: 'counttime'
});