Page 1 of 1

Auto Refresh

Posted: Tue Sep 18, 2012 10:07 am
by jimr
I have a program that in green-screen mode auto-refreshes using a *DTAQ.

I've "removed" all of the *DTAQ code in the program but would still like the screen to auto-refresh - at least on a predetermined period of time (like 'n' minutes). is there a way to do this using javascript on a PUI form?

Thanks,
Jim

Re: Auto Refresh

Posted: Tue Sep 18, 2012 11:03 am
by dieter
Jim,

a colleague did that with the following javascript snippet:
setTimeout("document.getElementById('TextBox1').value='5 seconds!' ",5000);

The script ist used in the Onload Event of the screen. It uses a field named "TextBox1" which shows the value "5 seconds!" every 5 seconds.


For refreshing the screen under control of an RPG program we use the following method: On the screen we have a textbox named "txtRefresh" with an assigned RPG-Field "REFRESH". In the Onload-Event of the screen we have the following javascript code:
if (getElementValue("txtRefresh")=="AUTO") { changeElementValue("txtRefresh", ' ');pui.click();};

So in our RPG-program we can assign the value "AUTO" to the variable REFRESH and than do an EXFMT. Then the javascript starts on the Onload event. It sets the screen element txtRefresh to blank (so the value "AUTO", which was set by the RPG program, is no longer in the field). Note that the element "txtRefresh" is dedicated to the RPG-variable "REFRESH"!). Than the script makes a "pui.click", so the control goes back from the browser to the RPG-Programm. With this method you can change variables on the screen via your RPG program and refresh the screen.

I hope you can understand my English. (I am from Germany).

Best regards,
Dieter

Re: Auto Refresh

Posted: Tue Sep 18, 2012 4:21 pm
by jimr
Thanks dieter,

I see what you are doing here - I want sort of a combination of the two. The subfile grid also needs to be usable during the timeout period. So far not working the way i want it too.

-jim

Re: Auto Refresh

Posted: Wed Sep 26, 2012 6:04 pm
by Antonio
Hello Jim,

I believe you could use the javascript function setTimeOut(expression, timeout) to accomplish what you need. What setTimeout() does is run expression after timeout milliseconds have gone past. So if you put the following line inside of the onload event of that screen:

setTimeout(function(){ pui.click()}, 3000);

It would refresh every 3 seconds. Let me know if you need further assistance.

Thanks!

Re: Auto Refresh

Posted: Sat Sep 29, 2012 5:33 pm
by jimr
Antonio,

That works pretty well. Is there a way I can control whether or not the java script runs from my RPG (turn it on and off) and modify the milliseconds with a variable? I assume there's a reason why none of the event properties can be bound to a field...

Thanks,
Jim

Re: Auto Refresh

Posted: Sat Sep 29, 2012 5:34 pm
by jimr
Antonio,

That works pretty well. Is there a way I can control whether or not the java script runs from my RPG (turn it on and off) and modify the milliseconds with a variable? I assume there's a reason why none of the event properties can be bound to a field...

Thanks,
Jim

Re: Auto Refresh

Posted: Sat Sep 29, 2012 11:25 pm
by Scott Klement
One way would be to include a hidden field on the screen containing the number of seconds (or milliseconds). Your JavaScript routine could check the value of the hidden field to get the timeout value -- or if a special value (maybe -1?) is found, it could choose not to do the setTimeout.

Re: Auto Refresh

Posted: Thu Jul 16, 2015 12:06 pm
by matts
Is there a way that I can allow the user to select the refresh interval? The onload screen refresh works perfectly but I would like to let the user select the amount of seconds between refreshes. If this is possible I could let them type in a value or select it from a dropdown box.

Thanks.

Re: Auto Refresh

Posted: Thu Jul 16, 2015 2:09 pm
by Scott Klement
Yes, you can have the user select it if you wish. You would probably want to code this on an 'onchange' event so that when the user selects a different time interval, it cancels the existing timer and sets up a new one.