How can I force a Day of the Week for a Week Starts On date field?

kevinfrost471
Mega Expert

I am trying to force a date field "Week Starts On" on my time card field to be a Sunday.   That is if a user selects a date that is a Tuesday for the week_starts_on I want to give and error message to them and abort the change to the field and have them try again to make it the Sunday of that week.

I have attempted to create a business rule for Before insert or update and added the following script to the Advanced tab of the business rule.

var wso = current.week_starts_on();

var dow = wso.getDay();

if (dow > 0){

      gs.addInfoMessage('Week Starts On Date Must Be a Sunday');

      current.week_starts_on.setError('Week Starts On Date Must Be a Sunday');

      current.setAbortAction(true);

}

Any and all help is appreciated.

1 ACCEPTED SOLUTION

kevinfrost471
Mega Expert

Thank you all!



Here is the solution i ended up getting to work:



var gdt = new GlideDateTime(current.week_starts_on);


if(gdt.getDayOfWeek()!=6){


      //gs.addInfoMessage('Week Starts On Date Must Be a Sunday');


      current.week_starts_on.setError('Week Starts On Date Must Be a Sunday');


      current.setAbortAction(true);


}


View solution in original post

10 REPLIES 10

kevinfrost471
Mega Expert

Thank you all!



Here is the solution i ended up getting to work:



var gdt = new GlideDateTime(current.week_starts_on);


if(gdt.getDayOfWeek()!=6){


      //gs.addInfoMessage('Week Starts On Date Must Be a Sunday');


      current.week_starts_on.setError('Week Starts On Date Must Be a Sunday');


      current.setAbortAction(true);


}