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

Nope

Can you please provide your scripts. Did you follow the exact steps mention above? Did you put the exact name of the fields?

Yes i followed.

 

Client script:

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

//Type appropriate comment here, and begin script below

var g4 = g_form.getValue("u_log_time");
var g5 = g_form.getValue("u_total_break_time");

var ajax = new GlideAjax('AjaxDurCalcTotal');
ajax.addParam('sysparm_name','durCalcTotal');
ajax.addParam('sysparm_strt2',g4);
ajax.addParam('sysparm_end2',g5);
ajax.getXMLWait();
//alert(ajax.getAnswer());
var answer2 = ajax.getAnswer();

g_form.setValue('u_total_time', answer2);

 

Script include:

 

var AjaxDurCalcTotal = Class.create();
AjaxDurCalcTotal.prototype = Object.extendsObject(AbstractAjaxProcessor, {
durCalcTotal: function(){

var duration1 = current.u_log_time; //or wherever your duration1 field is
var duration2 = current.u_total_break_time; //or wherever your duration2 field is
var duration = duration1.subtract(duration2);
var answer2 = duration.getDurationValue();


return answer2;

}

 

u_log_time and u_total_break_time are duration fields....

u_total_time is also a duration field

You need to set your duration variables to the values you are passing back in your glide ajax:

 

var AjaxDurCalcTotal = Class.create();
AjaxDurCalcTotal.prototype = Object.extendsObject(AbstractAjaxProcessor, {
durCalcTotal: function(){
var duration1 = this.getParameter('sysparm_strt2');
var duration2 = this.getParameter('sysparm_end2');
var duration = duration1.subtract(duration2);
var answer2 = duration.getDurationValue();
 
 
 return answer2;
}

venkataci
Kilo Contributor

yes..i have written the same way firstly...it did not worked

 

 

then i have used yours...even it has not worked..,