Skip to content

Commit 5bb9298

Browse files
authored
Restrict Time record submission on specific days. (#2213)
* script.js * README.md
1 parent f2fa2d6 commit 5bb9298

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Table: Time Worked [task_time_worked]
2+
Type: onsubmit
3+
4+
#Objective :
5+
Ensure that time entries (represented by the work_date field) are not submitted after 8:00 PM CST on two key dates:
6+
The 16th of the month and The last day of the month
7+
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.
8+
9+
#Business Scenario
10+
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.
11+
12+
The finance department requires that:
13+
On the 16th and last day of each month, submissions must be in before 8:00 PM CST.
14+
If employees miss the deadline, they can only log time for future dates (not today or the past).
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function onSubmit() {
2+
// Cutoff time for submission in CST.
3+
var cutoffTime = "20:00:00";
4+
5+
// Get the current date and time in CST
6+
var currentDate = new Date();
7+
var currentCSTDate = new Date(
8+
currentDate.toLocaleString("en-US", {
9+
timeZone: "America/Chicago"
10+
})
11+
);
12+
13+
// Get time from current CST date
14+
var currentCSTTime = currentCSTDate.toTimeString().substring(0, 8);
15+
16+
// Get last day of the month
17+
var dayOfMonth = currentCSTDate.getDate();
18+
var lastDayOfMonth = new Date(
19+
currentCSTDate.getFullYear(),
20+
currentCSTDate.getMonth() + 1,
21+
0
22+
).getDate();
23+
24+
if ((dayOfMonth === 16 || dayOfMonth === lastDayOfMonth) && currentCSTTime > cutoffTime) {
25+
var workDate = g_form.getValue("work_date");
26+
27+
if (workDate) {
28+
var formattedWorkDate = new Date(workDate + "T00:00:00");
29+
// If work_date is on or before current date, block submission
30+
if (formattedWorkDate <= currentCSTDate) {
31+
g_form.addErrorMessage(
32+
"The time period closed for time submission at 8:00 PM CST. Time must be billed in the next time period." + ": " + lastDayOfMonth
33+
);
34+
return false;
35+
}
36+
}
37+
}
38+
return true;
39+
}

0 commit comments

Comments
 (0)