I want to find the difference between the two date time fields and need to update in other duration field

venkataci
Kilo Contributor

I want to find the difference between the two date time fields and need to update in other duration field.

 

find_real_file.png   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:

find_real_file.png

 

 

Script include is:

 

find_real_file.png

 

Please help me to resolve it.

 

 

Thanks in Advance.

40 REPLIES 40

Can you please provide your code and the exact field name and type.

Yes..

 

Client script:

Type: onChange, Field Name: Log In Time

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
/* if (isLoading || newValue === '') {
return;
}*/

//Type appropriate comment here, and begin script below


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.getXMLWait();
alert(ajax.getAnswer());
var answer = ajax.getAnswer();

g_form.setValue('u_log_time', answer);
}

 

 

Script include:

var AjaxDurCalc = Class.create();
AjaxDurCalc.prototype =
Object.extendsObject(AbstractAjaxProcessor,{durCalc:function(){
return GlideDuration.subtract(this.getParameter('sysparm_strt'),this.getParameter('sysparm_end'));}});

 

I tried even with:

ar AjaxDurCalc = Class.create();
AjaxDurCalc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
durCalc: function() {
return gs.dateDiff(this.getParameter('sysparm_strt'),this.getParameter('sysparm_end'), false);
}
});

 

 

 

Your g1 variable is wrong. You've set it on u_log_off_time but the field name is u_logoff_time so your end time is a null value which is breaking the calculation. Correct it to below:

 

var g1 = g_form.getValue("u_logoff_time");

 

 

venkataci
Kilo Contributor

Got it ...

 

Thanks

How do i get the times in 24Hour format ?????