Help with Business rule to restrict date selection

alhicks
Tera Guru

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);
}
}

6 REPLIES 6

@Pradeep Sharma 

 

Hi Pradeep, I have the same issue, I wrote a business rule with

current.setAbortAction(true);
gs.addInfoMessage('MESSAGE YOU WANT TO PASS');

It's getting an error message when I am selecting future dates. But it's not redirecting to previous that has before I change the date. Can you please provide me how can I achieve.

I have actual start and end date in project task and it's populating with current stamp when I change the state to WIP,CC,CC,CS. If a user tried to change the those dates to future, It should restrict and nack to previous dates(before they edit dates). Please provide some help.

Sohithanjan G
Kilo Sage

Hi @alhicks 

you can try this

(function executeRule(current, previous /*null when async*/) {
    var date = gs.getMessage('Date cannot be before today');
    greaterThanOrEqualToToday(current.u_estimated_begin_date, date);
})(current, previous);

function greaterThanOrEqualToToday(value, errorMessage) {
    if (gs.dateDiff(gs.nowDateTime(), value.getDisplayValue(), true) < 0) {
        value.setError(errorMessage);
        current.setAbortAction(true);
    }
}


mark accepted if you get it