Timing Out A Screen



Sometimes, it's useful to have a screen that returns control to the program after a certain amount of time without the user having to press a key. In green-screen, you may have done this with data queues or the WAITRCD keyword but this will not work in a web browser. In web, the browser must do something in order for data to be exchanged between the browser and the server. Only when the browser requests a new screen will something happen. Imagine if any/all web servers out there could change your screen at any time (rather than just when you request it). A shopping site would pop up "special offers" whenever they felt like it. Spammers would pop up ads nonstop. It can't happen because a web server cannot initiate a screen. Profound UI cannot change that rule. Your DDS (or RPG) cannot tell the screen to "stop waiting for input". So something like WAITRCD that comes from the server cannot work in web.


You can make the screen stop waiting for input by adding some JavaScript in your display file. JavaScript runs in the browser, so it can initiate the request for something to happen. You would start a timer when the screen loads and have that timer submit the screen after a certain amount of time has passed. If the user submits the screen, you would have to cancel the timer so that it is not submitted twice. 


For example in the screen's onload event you could code this:




In the example above, setTimeout() starts a timer that will run a function after a certain number of milliseconds. In this case, the function runs pui.click() API which submits the screen. With no parameters, pui.click() is the same as pressing the ENTER key. This will run after 10000 milliseconds (which is 10 seconds).

To cancel the timer if the user submits the screen, you would set your onsubmit event to:



if (window.savedTimer != null) clearTimeout(window.savedTimer);




If you want to know that there was a timeout (vs. the user pressing enter) you can add a button to the screen and set its visibility to "hidden". That way, the user cannot click it. Change its "id" property to something like "timeoutButton". Bind its response property to an indicator like "TimedOut". Then, change the pui.click() to pui.click("timeoutButton") and that will cause the "TimedOut" indicator to be set to *ON in your program. That way you know that the screen timed out instead of the user hitting enter.