- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 01:00 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2016 06:51 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 01:20 PM
Kevina,
Whats the type of the field week_starts_on?
Is it date-time or date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 01:49 PM
It is a glide_date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 01:45 PM
This might help as I just recently worked on a timesheet application.
getWeekStartsOnByDate: function(date){
var mydate = new GlideDateTime(date + " 00:00:00");
var dow = mydate.getDayOfWeekUTC();
if (dow != 7) {
var days = '-' + dow;
mydate.addDaysUTC(days);
}
return mydate.getDate();
},
Note this is within a Fuji scoped application so this is using Scoped API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 01:53 PM
I am in Eureka at the moment. And the field i have "week_starts_on" is pre-populated and then the user can change it. I think your script is getting the day of the week but I need to run a check against that. Am i reading your script correctly?