- 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 02:00 PM
Kevin,
Have your script like this:
var wso = current.week_starts_on.getGlideObject();
var date = gd.getByFormat("dd-MM-yyyy");
var datesplit = date.split('-');
var day = datesplit[0];
if(day == '01')
{
gs.log('its sunday');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 02:49 PM
Mani,
I am not sure how this is the same that I am trying to do. I am trying to say that if the day of the week is not a Sunday to abort. Your script looks like it grabs the day of the date entered and if it is equal to 01 or the first of the month - say it is Sunday. Am I missing something? I need to evaluate the date entered - see what day of the week it is Sun Mon Tues etc and if not sunday then abort.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 02:59 PM
Kevin,
Basically you will change the code to
var wso = current.week_starts_on.getGlideObject();
var date = gd.getByFormat("dd-MM-yyyy");
var datesplit = date.split('-');
var day = datesplit[0];
if(day != '01')
{
current.setAbortAction(true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 02:02 PM
Any luck with this Kevin? Not sure why the "week starts on" is a free choice calendar, when you pre-select the day of the week to start on in time card properties...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2016 02:45 PM
The week starts on needs to be free choice so the user can choose a date to back date a time card they forgot to enter or enter a future one.