Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Table: Time Worked [task_time_worked]
Type: onsubmit

#Objective :
Ensure that time entries (represented by the work_date field) are not submitted after 8:00 PM CST on two key dates:
The 16th of the month and The last day of the month
If a user tries to submit time for a current or past date after the cut-off time, the submission is blocked and a clear error message is displayed.

#Business Scenario
Imagine a consulting firm where employees log billable hours against customer cases. There are internal controls in place that lock the timekeeping system after a certain cut-off time to ensure accurate payroll and billing.

The finance department requires that:
On the 16th and last day of each month, submissions must be in before 8:00 PM CST.
If employees miss the deadline, they can only log time for future dates (not today or the past).
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function onSubmit() {
// Cutoff time for submission in CST.
var cutoffTime = "20:00:00";

// Get the current date and time in CST
var currentDate = new Date();
var currentCSTDate = new Date(
currentDate.toLocaleString("en-US", {
timeZone: "America/Chicago"
})
);

// Get time from current CST date
var currentCSTTime = currentCSTDate.toTimeString().substring(0, 8);

// Get last day of the month
var dayOfMonth = currentCSTDate.getDate();
var lastDayOfMonth = new Date(
currentCSTDate.getFullYear(),
currentCSTDate.getMonth() + 1,
0
).getDate();

if ((dayOfMonth === 16 || dayOfMonth === lastDayOfMonth) && currentCSTTime > cutoffTime) {
var workDate = g_form.getValue("work_date");

if (workDate) {
var formattedWorkDate = new Date(workDate + "T00:00:00");
// If work_date is on or before current date, block submission
if (formattedWorkDate <= currentCSTDate) {
g_form.addErrorMessage(
"The time period closed for time submission at 8:00 PM CST. Time must be billed in the next time period." + ": " + lastDayOfMonth
);
return false;
}
}
}
return true;
}
Loading