1 2 Previous Next 19 Replies Latest reply: Jul 2, 2013 8:28 PM by scott.wesley Branched to a new discussion. RSS

    Fire dynamic action from javascript

    Ramesh P, Oracle APEX Developer

      Hi,

      Good evening.

      I am aware we can trigger dynamic actions in multiple ways based on events on the DOM.

      can some one help me triggering dynamic action from javascript.

      But not based on events.

       

      Ex: call dynamic action based on its name or sequence or some other way.

       

      There are situations where I need to call dynamic actions in order to avoid hand written Ajax calls.

       

      Thanks in advance

        • 1. Re: Fire dynamic action from javascript
          scott.wesley

          Do you have a use-case? You may be able to use dynamic actions anyway.

           

          Many questions are left unanswered with something outside the box because the question was missing it's goal.

          • 2. Re: Fire dynamic action from javascript
            Ramesh P, Oracle APEX Developer

            Hi Scott,

            Thanks for replying back.

            Let me walk you through the sample scenario why I need the javascript to fire dynamic action.

             

            I have report, with links that opens modal windows to enter some code values or other types of information based on information that is very specific to each record. So I have written javascript function to fire off by passing the parameters from the javascript function and set those values from the javascript function and then call the dynamic action to perform some server side events.

             

            In this perspective, I would like to trigger the dynamic action based on some conditions from javascript and user behavior.

             

            If you can help me out in calling DA's from JS that would be really great.

            • 3. Re: Fire dynamic action from javascript
              scott.wesley

              I'm not javascript expert so I won't comment on possible enhancements to that facet, but one idea came to mind.

               

              You could set the value of a P0_SIGNAL item (for argument's sake), and have an onChange even on P0_SIGNAL, potentially looking at specific values to execute relevant action.

               

              Might that work in your case?

              • 4. Re: Fire dynamic action from javascript
                VC

                RameshP,OracleAPEXDeveloper wrote:

                 

                Hi Scott,

                Thanks for replying back.

                Let me walk you through the sample scenario why I need the javascript to fire dynamic action.

                 

                I have report, with links that opens modal windows to enter some code values or other types of information based on information that is very specific to each record. So I have written javascript function to fire off by passing the parameters from the javascript function and set those values from the javascript function and then call the dynamic action to perform some server side events.

                 

                In this perspective, I would like to trigger the dynamic action based on some conditions from javascript and user behavior.

                 

                If you can help me out in calling DA's from JS that would be really great.

                Is it not possible to use dynamic actions instead of you javascript in first place?

                • 5. Re: Fire dynamic action from javascript
                  Ramesh P, Oracle APEX Developer

                  Hi VC,

                  As I am passing parameters from the javascript function which could be multiple at ttimes it would be hard.

                  I am also using dynamic actions in correlation with javascript.

                   

                  I heard in 4.2.* version its possible to fire dynamic action from javascript also, but not sure how to do that.

                  • 6. Re: Fire dynamic action from javascript
                    Ramesh P, Oracle APEX Developer

                    Hi Scott,

                    I also have same idea when doing this and approached this pattern but of no help.

                    The dynamic actions wouldn't trigger if the values are changed from the javascript

                    E: $("#P0_SIGNAL").val(123);

                     

                    That is the reason even this thread is opened, I can get things around using complete javascript making ajax calls but want to take advantage of DA's

                     

                    Thank you all.

                    • 7. Re: Fire dynamic action from javascript
                      Joe Upshaw

                      You can do this. Just define a Dynamic Action on some event that you never expect to fire and then trigger it from another JavaScript block using the apex.event.trigger command. Here is an example (I am firing the change event which, in turn fires the Dynamic Action tied to the change event):

                       

                      apex.event.trigger( $('#MARGIN_BUILDER_RR').find('input,select'),'change');

                       

                       

                      -Joe

                      • 8. Re: Fire dynamic action from javascript
                        Ramesh P, Oracle APEX Developer

                        Hi Jeo,

                        I tried your solution, but couldn't get the results, so I started playing little with your code and i finally got it.

                         

                        So here is what I have done to get it fired.

                        Create a hidden item and on that change have your dynamic action fired, but in fact in reality your dynamic action will never fire as it is hidden item.

                        So execute this code from javascript

                         

                        apex.event.trigger($("#P3_TEST_ID"),"change","");


                        When you create a dynamic action, make sure it fires on P3_TEST_ID page item change.

                         

                        I finally got it working one way or the other.

                         

                        But still not happy with the solution as its only a tweek instead ok executing the dynamic action by name or atleast its sequence order.

                        So giving it "HELPFUL"

                        • 9. Re: Fire dynamic action from javascript
                          Joe Upshaw

                          Ramesh,

                           

                          By definition,  Dynamic Actions are pre-defined *events* This means that they are call back routines that listen for some particular condition. For example, a click or a change or whatever. So, it isn't just that you can't call a Dynamic Action by its name, you can't call *any* event by its name. That just isn't what events are. Events are not named JavaScript routines. If you want to simply execute by name, then, as Scott suggested above, you would create JavaScript functions and just call them (by name).

                           

                          As to sequence order, I am not really sure what you mean.You could add several "True" scripts under the same DA and these would fire in the sequence that you specify. Also, you could add a bunch of hidden controls and tie multiple DAs to the change events. There's lots of ways to handle the sequencing.

                           

                           

                          -Joe

                          • 10. Re: Fire dynamic action from javascript
                            scott.wesley

                            Simpler to trigger using

                            $("#P0_SIGNAL").val(123).change();

                            • 11. Re: Fire dynamic action from javascript
                              Ramesh P, Oracle APEX Developer

                              Hi Scott,

                              I have tried these two techniques in which I am not successful.

                              $("#P0_SIGNAL").val(123).change(); -- Failed


                              $("#P0_SIGNAL").trigger("change");  --Failed


                              But anyways something like this
                              apex.event.trigger($("#P3_TEST_ID"),"change","");

                              I am able to get around,

                               

                              Thanks for all of your support in getting this task done.

                              I am pleased to have a community like this.

                               

                              Ramesh P.

                              • 12. Re: Fire dynamic action from javascript
                                scott.wesley

                                Can you describe why it failed? Errors? behaviour?

                                • 13. Re: Fire dynamic action from javascript
                                  Ramesh P, Oracle APEX Developer

                                  Hi Scott,

                                  Yeah surely I can explain.

                                  The dynamic actions that are intended to fire on calling the two failed codes didn't trigger the dynamic action to fire.

                                  • 14. Re: Fire dynamic action from javascript
                                    Ramesh P, Oracle APEX Developer

                                    Hi,

                                    The correct answer to this post:

                                    Not sure, why the following to lines of code didn't work to trigger a dynamic action

                                    $("#P0_SIGNAL").val(123).change(); -- Failed
                                    $("#P0_SIGNAL").trigger("change");  --Failed


                                    This line would trigger a dynamic action from javascript.
                                    apex.event.trigger($("#P3_TEST_ID"),"change","");


                                    Steps to make it working.


                                    I need to trigger a dynamic action when some value is set to hidden item from javascript


                                    P3_TEST_ID is a hidden item.

                                    Create a dynamic action to fire on P3_TEST_ID change event.

                                    Setting the p3_test_id value from javascript wouldn't trigger dynamic action.

                                    Execute the following code to fire DA from javascript

                                    apex.event.trigger($("#P3_TEST_ID"),"change","");

                                    1 2 Previous Next