Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

need client script to subtract two different date/Time fields and result would be stored in another field

malaisamy1
Kilo Contributor

Hi Guys,

Here i will explain my scenario,

We have two date fields. Those two dates need to be subtracted and the result should be stored in another field.

I need a client script for this.

Could anyone please help me on this.

Thanks in Advance,

Thanks,

Malaisamy

7 REPLIES 7

BALAJI40
Mega Sage

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


  var strt = g_form.getValue('<start_field>');//date1


  var end = g_form.getValue('<end_field>');//date2


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


}


});


Hi Balaji,



This i have tried but i am unable to achieve this. I will share my dev instance credentials..could you please help me on this



my Instance: ServiceNow



user: admin


pwd: Riyamalai*1



Table : Test Table(just type in navigation menu);



Calculation fields: Opened date/time, Investigation completed date



Result Field: SI Actual




Please use this and   help me


I will check....


Thanks.. I will be waiting for your reply