how to compare two date fields in application scope. I uses getGlideObject method but it is giving me the error as this function has been blocked from your application scope??

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2015 10:44 PM
I am using this code for comparing two date fields
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
if ((!current.today_s_date.nil())&& (!current.bill_generation_date.nil())) {
var start = current.today_s_date.getGlideObject().getNumericValue();
var end = current.bill_generation_date.getGlideObject().getNumericValue();
if (start > end) {
gs.addInfoMessage('bill generation date should not be greater than todays date');
current.today_s_date.setError('bill generation date should not be greater than todays date');
current.setAbortAction(true);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2015 01:37 AM
current.today_s_date is a GlideElement field.
The Scoped API for this object can be seen below.
You'll note there is no getGlideObject() method.
List of Scoped Scriptable Objects - ServiceNow Wiki
Scoped GlideElement API Reference - ServiceNow Wiki
GlideDate is the Glide object you want to work with Date fields.
List of Scoped Scriptable Objects - ServiceNow Wiki
GlideDateTime is the Glide object you want to work with DateTime fields.
http://wiki.servicenow.com/index.php?title=Scoped_GlideDateTime_API_Reference#gsc.tab=0
Try this code instead
function onBefore(current, previous) {
//This function will be automatically called when this rule is processed.
if ((!current.today_s_date.nil())&& (!current.bill_generation_date.nil())) {
var start = (new GlideDateTime(current.getValue('today_s_date'))).getNumericValue();
var end = (new GlideDateTime(current.getValue('bill_generation_date'))).getNumericValue();
if (start > end) {
gs.addInfoMessage('bill generation date should not be greater than todays date');
current.today_s_date.setError('bill generation date should not be greater than todays date');
current.setAbortAction(true);
}
}
}
Let me know if it works as I have not tested.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2017 03:27 AM
It works fine, the script you shared is the solution.
thank you