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

put an alert in your client script to confirm your getAnswer() method is returning the right value, i'm not familiar with the getAnswer method for getXMLWait.

venkataci
Kilo Contributor

Its not working David...

 

Its showing all 0's.

 

Alert is showing as NULL

venkataci
Kilo Contributor

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

Bhawana Upreti
Tera Guru

Hi,

You can use below code to calculate difference betweeen two dates.


On Click: getTimeDiff()

function getTimeDiff(){
var logIn = current.u_log_in_time.getGlideObject();
var logOff = current.u_log_off_time.getGlideObject();

current.u_log_time = gs.dateDiff(logIn.getDisplayValueInternal(),logOff.getDisplayValueInternal(),false);


}

OR as per your way you can try this.

 

Client script:

function onChange(control, oldValue, newValue, isLoading) {

  var strt = g_form.getValue('<start_field>');//set this as login date

  var end = g_form.getValue('<end_field>');//set this as logoff date

  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);

}

Script include

Name:AjaxDurCalc

Client callable:checked,client:checked

 

script:

var AjaxDurCalc = Class.create();

AjaxDurCalc.prototype = Object.extendsObject(AbstractAjaxProcessor, {

durCalc: function() {

return gs.dateDiff(this.getParameter('sysparm_strt'),this.getParameter('sysparm_end'), false);

}

});

if the post help you out, mark it as correct and helpful.

Thanks.

 

Hi Bhawana,

 

Thanks for reply but it is not working.

 

I am not seeing the calculated value in Total Log Time field.