
We have a business need to check if users are filling out time entry details in current time or if they are going back and updating after the time entry should be closed. On our time entry entity we have 4 fields actual start, actual end, time entry details and real time (yes/no). If focus is lost outside of the start and end time meaning if the user edits time entry details between those times (or if end time is null) then the time entry is considered real time if user edits the time entry details outside of the actual start and actual end times the time entry is considered not real time. I am pretty new to javascript so any help is very much appreciated!! Also not entirely sure if this should solely be on the field as an OnChange event or on the form as an OnLoad event or both. Thanks again!
I have this java script but it doesnt appear to be tracking the blur event correctly:
Hi,
What I understood:
When the user modifies the field e3_timeentrydetails, determine if it is a real time modification or not. Real time means that the change was made between the start and end date.
In javascript this would give a event handler that trigger on e3_timeentrydetails changes.
The field change event is triggered when the field has lost focus (click on another field, just before save the record, etc.).
Below is an event handler (called onTimeEntryDetailsChange) that modified the e3_realtime field accordingly:
function onTimeEntryDetailsChange(execCtx) {
const formCtx = execCtx.getFormContext();
const startAttr = formCtx.getAttribute("e3_actualstart");
const endAttr = formCtx.getAttribute("e3_actualend");
const realTimeAttr = formctx.getAttribute("e3_realtime");
const startDate = startAttr.getValue();
const endDate = endAttr.getValue();
const currentDate = new Date();
// Modified between time entry dates ?
const modifiedBetweenDate = (startDate != null && endDate != null && startDate < currentDate && endDate > currentDate);
realTimeAttr.setValue(modifiedBetweenDate);
}
This event handler must be registered to the on field change event of the e3_timeentrydetails field. Don't forget to check the "Pass execution context as first parameter" box when you register it.
This behavior can also be done via a real-time workflow, Power Automate or a plugin. These tools have the advantage of not being executed in the browser but on the server side, which means that the behavior would also be triggered if the field is modified by an external application (via API), an Excel import, etc. Let me know if you need it.