- 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
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
10-16-2020 01:35 PM
That works! Thank you. Why it is necessary if my suspended column is a Date/Time?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2020 01:44 PM
Hi,
I believe it's because you're passing the current record through to your script include as a function parameter and along the way the object type is changing to an element instead.
Anytime you're working with a field outside of the actual retrieval of that record, this can happen.
Please mark my above post as Helpful & Correct. Thank you and have a great weekend!
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
10-16-2020 01:49 PM
That's very good to know! Thank you again.