Help with Business rule to restrict date selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 08:13 AM
The below Before insert/update business rule is working as far as not selecting a date before the current date, but it won't accept the current date. The field is a date field only, not date/time on the project table.
(function executeRule(current, previous /*null when async*/) {
var date = gs.getMessage('Date cannot be before today');
greaterThanToday(current.u_estimated_begin_date, date);
})(current, previous);
function greaterThanToday(value, errorMessage) {
if(gs.dateDiff(gs.nowDateTime(), current.u_estimated_begin_date.getDisplayValue(),true)<0){
current.u_estimated_begin_date = '';
value.setError(errorMessage);
current.setAbortAction(true);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 08:22 AM
Hello,
If I get your requirement correctly you want to block a user from selecting date before than current date. In this case, you can create a BEFORE business rule and set the filter condition DATE FIELD is before today and under action,s tab set the Abort field to true with the message text you would like to display. No scripting is required in this case.
Screenshot for reference.
- Pradeep Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 08:52 AM
Thank you Pradeep, I had kinda played around with that before...:( Is there any way to clear out the date field if this happens or to put the message on the field level? Clearing at the field would be great..:)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 08:57 AM
Below thread should be helpful
https://community.servicenow.com/community?id=community_question&sys_id=abd88f61db5cdbc01dcaf3231f9619f5&anchor=answer_da8494f5db945fc01dcaf3231f96195f&view_source=searchResult
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2018 09:04 AM
Thanks for the update. In the actions tab uncheck the abort message and set the field value as DS | to | Leave date field blank and with script as
(function executeRule(current, previous /*null when async*/) {
// Add your code here
current.setAbortAction(true);
gs.addInfoMessage('MESSAGE YOU WANT TO PASS');
})(current, previous);
-pradeep Sharma