I am using APEX 26.1 and trying to auto refresh an Interactive Report region and page item “Last Refresh” (Date & Time of load or refresh) every 5 seconds.
I've been through a few iterations of this but none work completely.
The latest version successfully updates the Last Refresh, but the report does not.
The report query is basic:
SELECT sensor_id,
val_reading,
TO_CHAR(created_dt,'DD-MON-YYYY') date_logged,
to_char(created_dt, 'HH24:MI:SS') as time_logged
FROM sensor_log
ORDER BY created_dt DESC;
Items to Submit: P1_REFRESH_TRIGGER
(This will be explained below)
The refresh is trigger by JavaScript at the page level, in Execute when Page Loads:
(function() {
var counter = 0;
function doLiveUpdate() {
// 1. Update the visible timestamp instantly
var now = new Date();
var timeStr = now.toLocaleDateString() + ' ' + now.toLocaleTimeString();
apex.item("P1_LAST_REFRESH").setValue(timeStr);
// 2. Change the hidden item value to force APEX to drop its data cache
counter++;
apex.item("P1_REFRESH_TRIGGER").setValue(counter);
// 3. Fire the official modern refresh API
var irRegion = apex.region("sensors");
if (irRegion && typeof irRegion.refresh === "function") {
irRegion.refresh();
}
}
// Initialize immediately on page render
doLiveUpdate();
// Loop continuously every 5 seconds
setInterval(doLiveUpdate, 5000);
})();
The counter for P1_REFRESH_TRIGGER was added after multiple failed versions and a suggestion that a page item needed to change and be submitted with the query.
I test this by loading the page, inserting new data in the backend, and watching for the new data to be displayed.
I'd like to think there's an easy way to do this, but I'm not seeing it yet.
I'm willing to start over if that will help, since the page is extremely basic .
Thanks!