business rule to restrict date field selection

vinnus
Tera Contributor

business rule to restrict start date field to select from tomorrow only and end date field is from yesterday. 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

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 

SarthakKashyap_0-1714635260047.png

Highlighted date is selected from future , when I save this record it shows me the error 

SarthakKashyap_1-1714635345241.png

 

Please mark my answer correct and helpful if this works for you

 

Thanks and Regards 

Sarthak

View solution in original post

8 REPLIES 8

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

 

Try something like this

AnuragTripathi_0-1714577542254.png

 

AnuragTripathi_1-1714577558760.png

 

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?

-Anurag

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

vinnus
Tera Contributor

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

Seraj
Tera Guru

Hi @vinnus

 

Can you please explain more about your requirement