- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2020 01:10 PM
I have a table with a "suspended" column that is a Date/Time object. I wrote a business rule that calls a function in a script include:
deletable: function(current) {
if (current.state == 'suspended') {
var interval = gs.getProperty(x_ibmwa_gpra_polic.deleteSuspended);
var suspended = current.suspended;
var now = new GlideDateTime();
if (GlideDateTime.subtract(suspended, now).getDayPart() < interval) {
var msg = 'Cannot delete ' + current.getDisplayValue();
msg += '. Must be suspended for at least ' + interval + ' days.';
gs.addErrorMessage(msg);
current.setAbortAction(true);
}
}
}
The subtract fails with:
org.mozilla.javascript.EvaluatorException: Can't find method com.glide.glideobject.GlideDateTime.subtract(com.glide.script.glide_elements.GlideElementGlideObject,com.glide.script.fencing.ScopedGlideDateTime).
Why is suspended a GlideElementGlideObject and not a ScopedGlideDateTime? I found a reference to GlideElement.getRefRecord and tried:
var suspended = current.suspended.getRefRecord();
but the failure was the same.
Solved! Go to Solution.
- Labels:
-
Scoped App Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2020 01:24 PM
Hi,
Can you try using these lines for the suspended portion instead?
var suspended = current.suspended.getDisplayValue();
var suspendedTime = new GlideDateTime();
suspendedTime.setDisplayValue(suspended);
if (GlideDateTime.subtract(suspendedTime, now).getDayPart() < interval) {
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2021 02:15 AM
You can also make suspend a GlideDateTime Object
var suspended = (new GlideDateTime(current.getValue('suspended')));
This will solve the problem
Please mark reply as Helpful/Correct, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2021 06:00 AM
Hi,
In the Correct answer, I also made it a GlideDateTime object, just approached it differently with a few added steps to make sure it worked. What you did was do it in the same line, but in the end, it's the same thing that I did.
Thanks! 🙂
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!