Page 1 of 1

Execute Subroutne from OnChange Event

Posted: Tue May 07, 2019 3:49 pm
by mvaldman
I see that I can run a JavaScript from OnChange event. Is there a way to run an RPG subroutine (or get it to execute code below Exfmt)? I was thinking about making JavaScript press a hidden button, but don't want to re-invent the wheel if there is a prescribed method.
Thanks!!

Re: Execute Subroutne from OnChange Event

Posted: Wed May 08, 2019 10:37 am
by Scott Klement
Hi Max,

Subroutines and code beneath your EXFMT are internal parts of your RPG program. They can only be called from within that program.

The onchange event is JavaScript code that's running inside the web browser. It runs on your PC (Windows, Linux, MacOS, mobile device, or whatever you use to run your browser) so it is running in a different program on a different computer.

What people typically do instead is set the value of a field that gets returned to the RPG program. The most obvious way is to use the "changed" property of the widget to turn on an indicator, and when control is returned to the RPG program, it checks to see if the indicator is on and runs the subroutine.

Of course, that only makes sense if you don't mind waiting until the screen is submitted back to the RPG program. If you need to run code immediately when the field is changed, without submitting the screen, people will typically write that code in JavaScript. If it needs something from the server, it can use an AJAX call to a Universal Display (or a different web service / microservice) to get that information.

Re: Execute Subroutne from OnChange Event

Posted: Wed May 08, 2019 10:59 am
by mvaldman
Thank you Scott!

I was advised to use pui.click, which combined with changed indicator (like you suggested) does exactly what I need.
Thanks again.