• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

fireEvent from RPG button helper

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • fireEvent from RPG button helper


    Fire Event action & Event Listeners is working fine if it's front end only.

    fireEvent() from RPG button helper is working fine if the Event Listener is in the same app that called the RPG.

    fireEvent() from RPG button helper doesn't seem to be working when the RPG button helper is called from one app and the Event Listener is in a different app.

    I'm using the Event Listener in app1 (just sets an app variable). App1 will launch app2 which has the RPG button helper. I can see the event in the response from the button program: {"success" : true , "widget-form-1018" : { } , "fireEvent" : [ "PRINT_DELETEME1" ] } but Event Listener in app1 is not getting activated.

  • #2
    As of right now, back-end fired events only work with the application that called the back-end program.

    Comment


    • #3
      Ok, no worries... I can Execute Script on startup to add an event listener.

      Are there Valence.util.Helper functions to set app variables and/or call RPG from a script? Or will we have to just send Ajax request the old fashioned way (uphill both ways, no shoes, in the snow, etc. :cool: )?

      Comment


      • #4
        If you need to set app variables on the startup of an application you can do either (or both) of the following:
        • Specify a startup program (based off of EXNABSTART) and then call the SetAppVar procedure for each app variable you want to set
        • Specify the Set App Variables action under the "Startup" section in Behaviors
        What event listener would you be adding in a startup script?

        Comment


        • #5
          We have a bunch of menu options that produce reports. The program called directly from the menu is often just a screen to gather report parameters (from date, to date, division, etc.). When the user indicates they're ready to print, a utility program is called which presents the user with a pop-up window where they select an output queue, number of copies to print, and a few other things. The purpose of this utility is to save the user's printer settings (so that it will be the default next time the user wants to print this report) and also to set values in the *LDA (which our whole report routing system relies on). The user can press F12 at this point to cancel without printing, or Enter to accept the printer settings and continue. Control is returned to the calling program, and if the user wants to continue, the "real" report program is submitted to batch (and with just a little luck their report will print out where they wanted it to).

          We are working on the Valence version of the utility program that allows users to set printer settings for reports. It will be launched from other apps. The user will be able to Cancel (which will just close the printerSettings utility app) or they can accept the printer settings and continue. The report app which launched the reportSettings utility will need to know if/when it's ok to submit the "real" report-generation program to batch.

          I did a test with Fire Event and Event Listener and that works just fine. I was concerned, however, that there might be multiple report apps listening for that event at the same time... if any app caused the event to fire they would all submit their report to print. I didn't see a way to dynamically control the event name with an app variable (so that each calling app could listen for an event specific to that app) and I didn't see any way to add an object to the event where I could indicate which app should respond to the event (and didn't see any way to inspect the event object in the listening app anyway).

          So, then I tried send parms through the whole process and fire the event from the back-end RPG program. The event name was specific to the app which launched the utility program so that only that one app would be listening. That didn't work. :(

          Now, the report-generating app will be executing a script on startup that adds an event listener (listening for event `PRINT_${appId}`). The printerSettings utility program is calling a button helper (to save the settings to a file) and if it gets success back from that RPG it will execute a script to fireEvent(`PRINT_${callingAppId}`). This all works fine, but it's just doing an alert('Your stuff has printed')...just need to change that into an AJAX call to get the real report program submitted to batch, and then a call to showSnackbar to let the user know if the report program was submitted ok or not.

          Piece of cake ;)
          Seriously though if there's an easier way I'm all ears...

          Comment


          • #6
            I understand, thanks for detailed explanation. Your use case would require dynamic event names/listeners (as you stated) which is not supported.

            You could accomplish this without having to write any scripts but it would require a couple of work arounds at the moment so probably not worth it.

            If you are interested, something as follows may work:
            • Create an app variable named "reportId" (or similar) in your Printer Settings application.
              • Map this app variable to a URL parameter named "reportId".
            • For each report application that calls the Printer Settings application:
              • Pass the "reportId" parameter when launching the Printer Settings app. Pass a value that uniquely identifies this report.
              • Create an app variable named "printReportId"
            • Printer Settings app fires an event named "print_report". All report programs listen for the same "print_report" event.
            • The event listener for the "print_report" would perform 2 actions:
              • Set App Variables
                • Set the value of "printReportId" to the "reportId" parameter passed by the event
                  • App variables from the Printer Settings application will be available as "Event Parameters"
              • Call RPG Program
                • Your RPG program would have access to the "printReportId" app variable. If it matches that of the report then submit the job...otherwise do nothing.
            As you can see, we would have to introduce a potentially unnecessary RPG call into the mix. In a future build, we should have a way to conditionally not run the actions beneath an event listener.


            Comment


            • #7
              Thanks! Yeah, that's another way to go... just need to decide if we want to code the Ext.Ajax.request ourselves (which is the route I have gone for now) or let all the listeners call the RPG and use app variables to stop the press at that point.

              Looking forward to the NAB event listener being able to conditionally execute the actions beneath it (based on the event object or some other magic that you guys come up with)!

              Comment

              Working...
              X