Minimum 40 hours to submit in timesheet portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 04:40 AM
Hi Team,
I am working on a requirement for making minimum 40 hours time card to be submitted in a week. I have tried below business rule but it is working past week and future weeks but not current week. Please help in fixing the issue :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 05:45 AM
Ok, but what happens on weeks with holidays, sick days, etc?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 06:17 AM
Hi Maneesh - Try this
(function executeRule(current, previous /*null when creating*/) {
var totalHours = 0;
// Get the start date of the current week (assuming week starts on Monday)
var weekStartDate = new GlideDateTime();
weekStartDate.setDisplayValue(current.week_starts_on); // Assuming this is the field for the week start date
weekStartDate.setDayOfWeek(2); // Set to Monday (1 = Sunday, 2 = Monday, etc.)
weekStartDate.setStartOfDay();
// Get the end date of the current week
var weekEndDate = new GlideDateTime(weekStartDate);
weekEndDate.addDays(6);
weekEndDate.setEndOfDay();
// Query all time entries for the current week
var timeCardGR = new GlideRecord('time_card');
timeCardGR.addQuery('week_starts_on', '>=', weekStartDate);
timeCardGR.addQuery('week_starts_on', '<=', weekEndDate);
timeCardGR.query();
while (timeCardGR.next()) {
totalHours += parseFloat(timeCardGR.total); // Assuming "total" is the field for the time logged
}
// If the total hours for the week are less than 40, prevent the save
if (totalHours < 40) {
gs.addErrorMessage('You must submit at least 40 hours for the current week.');
current.setAbortAction(true); // Prevent the time entry from being saved
}
})(current, previous);
If found useful, click on like button.
Best,
PC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 07:56 AM
Hi Prabhakar,
Thanks for the reply. It is working but still it wont stop for current week, past and future weeks it is working
It is allowing current week.
below is my portal look:
i have used before BR and Update action with condition as State changes to Submitted
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2024 11:08 AM
Hi Prabhakar,
Can you please suggest