Calculate duration in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2020 12:13 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2020 12:30 PM
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2020 12:48 PM
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