Calculate duration in client script

aaron_anderson
Tera Expert

Is there something missing from https://docs.servicenow.com/bundle/london-application-development/page/script/general-scripting/conc... that shows how a client script can return a duration?

Below is the script I'm using with additional alerts to show what we're actually getting. The dates look fine but the answer returns null. Below the client script is the ajax script include. When I return a specific value it did work but when I use the subtract it returns null instead.

 

find_real_file.png

 

find_real_file.png

2 REPLIES 2

Jaspal Singh
Mega Patron
Mega Patron

In your script include can you use below

var startdate=this.getParameter('sysparm_strt').getDisplayValue();
gs.log('Start date is ',startdate);

var enddate=this.getParameter('sysparm_end').getDisplayValue();
gs.log('End date is ',enddate);

var subtractionis=GlideDateTime.subtract(startdate,enddate);
gs.log('Subraction is ',subtractionis);

return subtractionis; 

 

Hemant Goldar
Mega Sage
Mega Sage

Hi,

You may find the below thread helpful.
https://community.servicenow.com/community?id=community_question&sys_id=b9d90329db5cdbc01dcaf3231f96...


Hope this helps!

Please mark the reply as Helpful/Correct, if applicable.

Regards,
Hemant