- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 08:17 AM
business rule to restrict start date field to select from tomorrow only and end date field is from yesterday.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2024 12:36 AM
Hi @vinnus ,
Oh okayy now I'm clear with your reqiurments you can use below code now
It will work for you
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var currentDate = new GlideDateTime();
var startDate = current.start_date;
var endDate = current.end_date;
var convertStartDate = new GlideDateTime(startDate);
var convertEndDate = new GlideDateTime(endDate);
gs.log('Inside Restrict Date ' + currentDate + " SatrtDate = " + convertStartDate + " End Date = " + convertEndDate);
if (currentDate.compareTo(convertStartDate) == -1 || currentDate.compareTo(convertStartDate) == 0) {
gs.log("Inside if 2");
gs.addErrorMessage("Can not select from future");
current.setAbortAction(true);
}
})(current, previous);
Result
Highlighted date is selected from future , when I save this record it shows me the error
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 08:32 AM - edited 05-01-2024 08:34 AM
Hi,
Try something like this
You will need to have separate BR for Start and end date.
Also in your question you said Start Date as tomorrow and End date as yesterday, I'm not sure of that was intentional or mistake. how can a task start in future and end in past?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 09:37 AM
BR to restrict the select the end date field is from yesterday onwards only, and clear the field if current and future date is selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 09:41 AM
BR to restrict the select the end date field current and future date and can only select from yesterday onwards only, and clear the field if current and future date is selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2024 09:04 AM