I want to find the difference between the two date time fields and need to update in other duration field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 02:45 AM
I want to find the difference between the two date time fields and need to update in other duration field.
Log in Time and Logoff time are Date/ Time fields and Total Log time is duration field.
I have written server side script for this to work calling a glide ajax call. But it is not calculating the difference.
Client script:
Script include is:
Please help me to resolve it.
Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 06:21 AM
Which times do you want in 24 hour format? The value should be as per your system set time format but you could try changing your g and g1 variables to getDisplayValue() rather than getValue().
If it's working now please mark an answer correct to close the thread down.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 05:00 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 05:22 AM
Did you try to change the field name of "u_log_off_time" to "u_logoff_time"??
Also. Please change scipt include code to the below code.
return gs.dateDiff(this.getParameter('sysparm_strt'),this.getParameter('sysparm_end'), false);
I have tried it in my demo instance and it working absolutely fine.
Mark post as correct and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 05:38 AM
Got it..did not chkd ...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 06:04 AM
Try with below code,
In Client script,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var g = g_form.getValue("u_log_in_time");
var g1 = g_form.getValue("u_log_off_time");
var ajax = new GlideAjax('AjaxDurCalc');
ajax.addParam('sysparm_name','durCalc');
ajax.addParam('sysparm_strt',g);
ajax.addParam('sysparm_end',g1);
ajax.getXML(GetAnswer);
function GetAnswer(response) {
var answer= response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('u_total_log', answer);
}
}
In script include,
var AjaxDurCalc = Class.create();
AjaxDurCalc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
durCalc:function(){
var start=new GlideDateTime(this.getParameter('sysparm_strt'));
var end=new GlideDateTime(this.getParameter('sysparm_end'));
var dur = GlideDateTime.subtract(start,end);
gs.info("duration "+dur.getDisplayValue());
return dur;
},
type: 'AjaxDurCalc'
});