- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 08:59 AM
I have 2 datetime fields and also have a duration (single line of text). I am trying to compute the difference between the start and end date and put the difference in the duration field.
I am having a difficult time figuring this out via client script, this is on a service catalog item. I tried to use the "gs" api, but it frowns upon that in client scripts. I then tried this and still no luck:
var startDate = g_form.getValue("start_date");
var endDate = g_form.getValue("end_date");
alert(startDate + " ," + endDate);
var dc = new DurationCalculator();
var dur = dc.calcScheduleDuration(startDate, endDate);
alert(dur);
Any advice?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 09:37 AM
Hi Josh
Methods of duration calculator can be used only on the server side. Make an Ajax call and use this method in script include.
You can also use GlideSchedule for duration calculation.
Thanks
Abhinandan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 09:31 AM
What are your alerts returning? Try something like this:
var sd = g_form.getValue("start_date");
var ed = g_form.getValue("end_date");
var startDate = new GlideDateTime(sd);
var endDate = new GlideDateTime(ed);
var dif = gs.dateDiff(startDate, endDate, false);
alert(dif);
Cheers,
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 09:33 AM
I am unable to use "gs" in client scripts..... I get this error :
The object "gs" should not be used in client scripts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 09:33 AM
Ah, right, sorry...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2016 09:35 AM
Are there any other options?