- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2015 09:07 AM
Good morning Community,
Can someone recommend a way to obtain DurationCalculator functionality within a non-global scoped application?
I'm working on an app that needs to calculate raw duration and schedule duration between two dates and would like to use the DurationCalculator script include. Unfortunately, the DurationCalculator script include is marked as available within "This application scope only", and a call to gs.include('DurationCalculator'); fails with the following:
org.mozilla.javascript.EcmaError: "DurationCalculator" is not defined.
Caused by error in Script Action: 'myScriptAction' at line 6
3: */
4: gs.include('global.DurationCalculator');
5:
==> 6: myScriptAction(event, current);
7:
8: function myScriptAction(event, current) {
9: /*
(function names changed to protect the innocent)
There doesn't appear to be an easy way around this. I could opt to not use DurationCalculator, or I could change my scope to Global. I could also duplicate the DurationCalculator functionality in my app. None of these options are desirable.
See also: Scripting in Scoped Applications:Public and Private Script Includes
Thanks in advance for any ideas.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2015 02:28 PM
I ended up foregoing the DurationCalculator functionality and instead used the other scoped API methods for calculating duration, namely:
Scoped GlideSchedule API:
GlideSchedule.duration(GlideDateTime startDate, GlideDateTime endDate);
Example (modified from wiki as the schedule.load() call will fail in a scoped app):
var startDate = new GlideDateTime('2014-10-16 02:00:00');
var endDate = new GlideDateTime('2014-10-18 04:00:00');
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828', gs.getProperty('glide.sys.default.tz'));
// The following commented line won't work in a scoped application:
// schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding holidays" schedule
var duration = schedule.duration(startDate, endDate);
gs.info(duration.getDurationValue()); // gets the elapsed time in schedule
and
Scoped GlideDateTime API:
GlideDateTime.subtract(GlideDateTime start, GlideDateTime end);
Example (from the wiki):
var gdt1 = new GlideDateTime("2011-08-28 09:00:00");
var gdt2 = new GlideDateTime("2011-08-31 08:00:00");
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
gs.info(dur.getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2015 07:27 AM
? Can you not change the setting to "All application scopes" ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2015 02:14 PM
Thanks Mike. That would solve the issue, but I'd prefer not to, as doing so would run contrary to scoping my app.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2015 02:28 PM
I ended up foregoing the DurationCalculator functionality and instead used the other scoped API methods for calculating duration, namely:
Scoped GlideSchedule API:
GlideSchedule.duration(GlideDateTime startDate, GlideDateTime endDate);
Example (modified from wiki as the schedule.load() call will fail in a scoped app):
var startDate = new GlideDateTime('2014-10-16 02:00:00');
var endDate = new GlideDateTime('2014-10-18 04:00:00');
var schedule = new GlideSchedule('090eecae0a0a0b260077e1dfa71da828', gs.getProperty('glide.sys.default.tz'));
// The following commented line won't work in a scoped application:
// schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding holidays" schedule
var duration = schedule.duration(startDate, endDate);
gs.info(duration.getDurationValue()); // gets the elapsed time in schedule
and
Scoped GlideDateTime API:
GlideDateTime.subtract(GlideDateTime start, GlideDateTime end);
Example (from the wiki):
var gdt1 = new GlideDateTime("2011-08-28 09:00:00");
var gdt2 = new GlideDateTime("2011-08-31 08:00:00");
var dur = GlideDateTime.subtract(gdt1, gdt2); //the difference between gdt1 and gdt2
gs.info(dur.getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2020 07:10 PM
Hi
duration.getDurationValue()
Trying out your example gives me something in HH:mm:ss format. Can I assign this value on a table column with type Duration?
Thank you so much!