- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2016 07:32 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2016 06:50 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 02:20 PM
Joe could you please share how you did this?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 02:44 PM
Makes sense but not sure on the coding (sorry coding newbie relatively).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 02:33 PM
You could also just make it change it to the preceding Sunday automatically if they choose another day. If getDayOfWeekLocalTime() != 7, get the day of the week and subtract it that many... addDaysLocalTime(-(getDayOfWeekLocalTime()) or something because a Monday (1) will subtract a day making it Sunday, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 02:42 PM
Will this work on a calendar field - the user can select any date they want. We do this so they can create future time cards or enter one for last week because they forgot. So If i chose Tuesday of last week I need it to either go to Sunday of last week or tell me I have to choose a Sunday.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 02:45 PM
Yeah, using an OnChange client script that calls an asynchronous GlideAjax script include and passes the newValue to the server for it to figure out and return the previous Sunday should work. It would probably run twice though, cause the first time will check if it's a Sunday and then make it a Sunday, and the onChange will run again to see if it's a Sunday and then be good and not make another change.