The CreatorCon Call for Content is officially open! Get started here.

How can I force a date field to be a Sunday?

kevinfrost471
Mega Expert

I have a date field on my time card form that is a "Week Starts on Date".   This needs to be a Sunday however right now the end user can chose any date.     What I want to do is to force them to use a Sunday.     (It can be a Monday if necessary).       If a user chooses a Tuesday I want the field to populate with the Sunday of that week and notify the users that we have done that.   Any help is greatly appreciated.

1 ACCEPTED SOLUTION

kevinfrost471
Mega Expert

Thank you to all!  



Here is the business rule I ended up putting in place - the is a before rule for insert and update:



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

19 REPLIES 19

I also tried with just 'week_starts_on' but it did not work - also the { after the onSubmit seemed to be required for syntax


Ok sorry partly user error....I have created the Client Script and the Script include now.   The warning flashes up on the screen but it still allows the time card to be submitted.   The error flashed up and then disappered and brought me to the list of time cards with the new one there with the incorrect date.  



How do I bring them back to the time card?


The return false part should stop the submission.   Let me run some tests and see if I can get it to stop.


Thank you Mike - let me know how it goes!  


Sorry that I'm late to this but I just worked through a very similar issue. You can avoid the loop by using a switch statement (switching based on day of week) and when you hit sunday in the switch do nothing...that gets you out of the loop. Make sense?