Calculate duration

siva118
Tera Contributor

Create a duration field (field type: duration) on the item order table and calculate the duration between the creation time and the present time of the record

1 ACCEPTED SOLUTION

dgarad
Giga Sage

Hi @siva118 

 

 Create Script Include 

var AjaxDurCalcToday = Class.create();


AjaxDurCalcToday.prototype = Object.extendsObject(AbstractAjaxProcessor, {


       durCalcToday: function() {


               return gs.dateDiff(this.getParameter('sysparm_strt'),new GlideDateTime().getDisplayValue(), false);


       }


});

 

And the onLoad client script 

function onLoad() {


       var strt = g_form.getValue('sys_created_on'); 


       var ajax = new GlideAjax('AjaxDurCalcToday'); 


       ajax.addParam('sysparm_name','durCalcToday'); 


       ajax.addParam('sysparm_strt',strt); 


       ajax.getXMLWait(); 


       var answer = ajax.getAnswer(); 


       g_form.setValue('u_total_time_open', answer); 


}
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

View solution in original post

3 REPLIES 3

-O-
Kilo Patron
Kilo Patron

Is this a random thought? A question? Something else?

dgarad
Giga Sage

Hi @siva118 

 

 Create Script Include 

var AjaxDurCalcToday = Class.create();


AjaxDurCalcToday.prototype = Object.extendsObject(AbstractAjaxProcessor, {


       durCalcToday: function() {


               return gs.dateDiff(this.getParameter('sysparm_strt'),new GlideDateTime().getDisplayValue(), false);


       }


});

 

And the onLoad client script 

function onLoad() {


       var strt = g_form.getValue('sys_created_on'); 


       var ajax = new GlideAjax('AjaxDurCalcToday'); 


       ajax.addParam('sysparm_name','durCalcToday'); 


       ajax.addParam('sysparm_strt',strt); 


       ajax.getXMLWait(); 


       var answer = ajax.getAnswer(); 


       g_form.setValue('u_total_time_open', answer); 


}
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

siva118
Tera Contributor

It's working Awesome 

Thank you

Sivanjaneyulu Bellamkonda