- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2024 08:21 PM
I have a date validation business rule that uses the following script:
(function executeRule(current, previous /*null when async*/) {
var workStartElem = current.planned_start_date;
var workEndElem = current.planned_end_date;
var workStartGDT = workStartElem.getGlideObject();
var workEndGDT = workEndElem.getGlideObject();
if (workStartGDT.after(workEndGDT)) {
gs.addErrorMessage(gs.getMessage("{0} must be after {1}", [ workEndElem.getLabel(), workStartElem.getLabel() ]));
current.setAbortAction(true);
return;
}
// The method of duration calculation is used instead of a condition (in the condition builder)
// to ensure we use the same method of comparison between client and server
var FIFTY_YEARS_MILLIS = 1576800000000; // 1000 * 60 * 60 * 24 * 365 * 50
var duration = GlideDateTime.subtract(workStartGDT, workEndGDT).getNumericValue();
if (duration > FIFTY_YEARS_MILLIS) {
gs.addErrorMessage(gs.getMessage("{0} cannot be more than 50 years after {1}", [ workEndElem.getLabel(), workStartElem.getLabel() ]));
current.setAbortAction(true);
}
})(current, previous);
This script is from a global business rule and it uses getGlideObject() in lines 4 and 5 which is not supported in my custom scoped application and is throwing an error stating:Function getGlideObject is not allowed in scope x_g_#####.
Thank you in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2024 03:03 AM
Can you try using GlideDateTime
(function executeRule(current, previous /*null when async*/) {
var workStartElem = current.planned_start_date;
var workEndElem = current.planned_end_date;
// Create GlideDateTime objects directly
var workStartGDT = new GlideDateTime(workStartElem);
var workEndGDT = new GlideDateTime(workEndElem);
if (workStartGDT.after(workEndGDT)) {
gs.addErrorMessage(gs.getMessage("{0} must be after {1}", [ workEndElem.getLabel(), workStartElem.getLabel() ]));
current.setAbortAction(true);
return;
}
// The method of duration calculation is used instead of a condition (in the condition builder)
// to ensure we use the same method of comparison between client and server
var FIFTY_YEARS_MILLIS = 1576800000000; // 1000 * 60 * 60 * 24 * 365 * 50
var duration = GlideDateTime.subtract(workStartGDT, workEndGDT).getNumericValue();
if (duration > FIFTY_YEARS_MILLIS) {
gs.addErrorMessage(gs.getMessage("{0} cannot be more than 50 years after {1}", [ workEndElem.getLabel(), workStartElem.getLabel() ]));
current.setAbortAction(true);
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2024 03:03 AM
Can you try using GlideDateTime
(function executeRule(current, previous /*null when async*/) {
var workStartElem = current.planned_start_date;
var workEndElem = current.planned_end_date;
// Create GlideDateTime objects directly
var workStartGDT = new GlideDateTime(workStartElem);
var workEndGDT = new GlideDateTime(workEndElem);
if (workStartGDT.after(workEndGDT)) {
gs.addErrorMessage(gs.getMessage("{0} must be after {1}", [ workEndElem.getLabel(), workStartElem.getLabel() ]));
current.setAbortAction(true);
return;
}
// The method of duration calculation is used instead of a condition (in the condition builder)
// to ensure we use the same method of comparison between client and server
var FIFTY_YEARS_MILLIS = 1576800000000; // 1000 * 60 * 60 * 24 * 365 * 50
var duration = GlideDateTime.subtract(workStartGDT, workEndGDT).getNumericValue();
if (duration > FIFTY_YEARS_MILLIS) {
gs.addErrorMessage(gs.getMessage("{0} cannot be more than 50 years after {1}", [ workEndElem.getLabel(), workStartElem.getLabel() ]));
current.setAbortAction(true);
}
})(current, previous);
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2024 04:36 AM
Hi @Navaneeth1 ,
You can use new GlideDateTime(<your Variable name>). I checked in my PDI this will work for you
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak