13 Replies Latest reply on Jul 20, 2017 1:46 AM by swesley_perth

    apex.server.process Success Function in APEX 5.1.2 - Has something Changed?

    Tony F.

      Hi,

       

      Using Oracle APEX 5.1.2.

       

      Having been someone who's worked on Oracle APEX 4.2 for a while and now working with 5.1.2 and reading that things have changed with the whole async process of AJAX cxalls, I'm still trying to understand what has changed and why the following code no longer seems to work (unless I'm doing something wrong).

       

      My code is:

       

      apex.server.process('GET_TYPE_VALUE',

                          {pageItems: '#P3_TYPE'},

                          {success: function(data){

                                       $s("P3_VALUE", data);

                                    },

                           dataType: "text",

                           loadingIndicator: '#P3_VALUE'}

                          );

       

      The code that I'm finding no longer works is the code within the "success" function and unfortunately I'm unsure why? Is there a new way of using apex.server.process within Oracle APEX 5.1.2?

       

      Would really appreciate your help/examples of correct usage in 5.1.2.

       

      Thanks.

       

      Tony.

        • 1. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
          fac586

          Tony F. wrote:

           

          Using Oracle APEX 5.1.2.

           

          Having been someone who's worked on Oracle APEX 4.2 for a while and now working with 5.1.2 and reading that things have changed with the whole async process of AJAX cxalls, I'm still trying to understand what has changed and why the following code no longer seems to work (unless I'm doing something wrong).

           

          My code is:

           

          apex.server.process('GET_TYPE_VALUE',

          {pageItems: '#P3_TYPE'},

          {success: function(data){

          $s("P3_VALUE", data);

          },

          dataType: "text",

          loadingIndicator: '#P3_VALUE'}

          );

           

          The code that I'm finding no longer works is the code within the "success" function and unfortunately I'm unsure why? Is there a new way of using apex.server.process within Oracle APEX 5.1.2?

          Where is this code located and when is it executed?

           

          Any errors logged in the browser console?

          • 2. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
            Kiran Pawar

            Hi Tony F.,

            Tony F. wrote:

             

            Using Oracle APEX 5.1.2.

            Having been someone who's worked on Oracle APEX 4.2 for a while and now working with 5.1.2 and reading that things have changed with the whole async process of AJAX cxalls, I'm still trying to understand what has changed and why the following code no longer seems to work (unless I'm doing something wrong).

            My code is:

            apex.server.process('GET_TYPE_VALUE',

            {pageItems: '#P3_TYPE'},

            {success: function(data){

            $s("P3_VALUE", data);

            },

            dataType: "text",

            loadingIndicator: '#P3_VALUE'}

            );

             

            The code that I'm finding no longer works is the code within the "success" function and unfortunately I'm unsure why? Is there a new way of using apex.server.process within Oracle APEX 5.1.2?

            Would really appreciate your help/examples of correct usage in 5.1.2.

            There is nothing wrong with apex.server.process JavaScript API in APEX 5.1.2.

            Refer: apex.server namespace

            The issue lies with following legacy JavaScript API you are using to set Item Value:

            $s("P3_VALUE", data);
            

            If you still want to use legacy JavaScript API, you should enable the legacy javascript in interface attribute:

            Refer: Managing Application Attributes

            Instead you should use:

            apex.item("P3_VALUE").setValue(data);
            

            Refer: apex.item

            Hence, your JavaScript code above should be:

            apex.server.process('GET_TYPE_VALUE',
                                {pageItems: '#P3_TYPE'},
                                {success: function(data){
                                             apex.item("P3_VALUE").setValue(data);
                                          },
                                 dataType: "text",
                                 loadingIndicator: '#P3_VALUE'}
                                );
            

             

            Also, are you just trying this out? (from this blog: Tom's Blog: Ajax in Apex: introduction and techniques )

            In that case you have to make sure:

            • You should create GET_TYPE_VALUE (AJAX Callback/Application Process) at least with minimum code as:
            BEGIN
            SYS.HTP.P(:P3_TYPE);
            END;
            
            • Make sure you have created page items P3_TYPE and P3_VALUE.
            • Enclose the apex.server.process code above in JavaScript function as follows and include in Page Attributes -> JavaScript -> Function and Global Variable Declaration section of the page:
            function typeChange() {
            apex.server.process('GET_TYPE_VALUE',
                                {pageItems: '#P3_TYPE'},
                                {success: function(data){
                                             apex.item("P3_VALUE").setValue(data);
                                          },
                                 dataType: "text",
                                 loadingIndicator: '#P3_VALUE'}
                                );
            }
            
            • Call the JavaScript function "onchange" event of the P3_TYPE item (Item Attributes -> HTML Form Element Attributes):
            onchange="typeChange()"
            

             

            Working example: https://apex.oracle.com/pls/apex/f?p=14644:1  (demo/demo)

             

            Hope this helps!

             

            Regards,

            Kiran

            • 3. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
              fac586

              Kiran Pawar wrote:

               

              The issue lies with following legacy JavaScript API you are using to set Item Value:

              1. $s("P3_VALUE",data);

              If you still want to use legacy JavaScript API, you should enable the legacy javascript in interface attribute

              $s (and $x, $v, and $v2) are not deprecated and do not require the Include Legacy JavaScript property to be set.

               

              Why don't we wait until we have sufficient information to enable us to understand the problem before embarking on attempts to solve it?

              • 4. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
                Tony F.

                Hi Kiran,

                 

                FYI, I have done what you have suggested but for some reason my console.log message is not appearing as part of my success section, i.e.:

                 

                function createRec() {
                    apex.server.process('CREATEREC',
                        {
                          pageItems: '#P5_SEQ_ID'
                        },
                        {
                          dataType: "text",
                          success:  function(pNo){
                                      if (parseInt(pNo) > 0){
                                          console.log("pNo is: "+pNo);
                                          apex.item("P5_REF_NO").setValue(pNo);
                                      }           
                                  }
                        }
                    );
                }
                

                 

                I'm not receiving any JS errors but the only difference to your steps is that I am calling my apex.server.process function from a Dynamic Action and further to this, my actual AJAX Callback - CREATEREC exists within my actual page 5.

                 

                From what I can see, the call is made and seems to work and I do have 

                SYS.HTP.P(:P5_REF_NO);
                

                 

                within my AJAX Callback but I am not seeing my console.log message appearing.

                 

                Any ideas as I need to check for errors during these AJAX Callbacks?

                 

                Perhaps, is there a better way of doing this as I may need to check a few AJAX callbacks?

                 

                Thanks again.

                 

                Tony.

                • 5. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
                  Kiran Pawar

                  Hi Tony F.,

                  Tony F. wrote:

                   

                  FYI, I have done what you have suggested but for some reason my console.log message is not appearing as part of my success section, i.e.:

                  ...

                  I'm not receiving any JS errors but the only difference to your steps is that I am calling my apex.server.process function from a Dynamic Action and further to this, my actual AJAX Callback - CREATEREC exists within my actual page 5.

                  From what I can see, the call is made and seems to work and I do have

                  1. SYS.HTP.P(:P5_REF_NO);

                  within my AJAX Callback but I am not seeing my console.log message appearing.

                  Any ideas as I need to check for errors during these AJAX Callbacks?

                  Perhaps, is there a better way of doing this as I may need to check a few AJAX callbacks?

                  I think you are setting the session value of P5_SEQ_ID in your JS AJAX call using apex.server.process. Hence, you should return:

                  SYS.HTP.P(:P5_SEQ_ID);
                  

                  in your AJAX Callback ODP (on-demand process).

                  Then set that value to P5_REF_NO using apex.item JS API.

                   

                  You can use Chrome Developer Tools (Network tab) to monitor/debug the AJAX calls in Google Chrome, or Firebug extension in Mozilla Firefox to monitor/debug the AJAX calls.

                   

                  Hope this helps!

                   

                  Regards,

                  Kiran

                  • 6. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
                    Tony F.

                    Thanks for coming back. The thing that puzzles me is why doesn't my console.log fire as I can't tell if it's actually going into the "success"?

                     

                    Furthermore, unsure how to capture/debug my AJAX call in Chrome Devtools when it's been done within a modal window?

                     

                    Thanks.

                    • 7. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
                      Kiran Pawar

                      Hi Tony F.,

                      Tony F. wrote:

                       

                      Thanks for coming back. The thing that puzzles me is why doesn't my console.log fire as I can't tell if it's actually going into the "success"?

                      Furthermore, unsure how to capture/debug my AJAX call in Chrome Devtools when it's been done within a modal window?

                      By adding:

                      console.log(data);
                      

                      in my code success option for apex.server.process i was able to see the data:

                      chrome_console.png

                       

                      You may be monitoring AJAX call in Network tab, switch to Console tab (make sure all messages are show, instead of specific) in Chrome Developer Tools:

                      chrome_console_1.png

                       

                      Hope this helps!

                       

                      Regards,

                      Kiran

                      • 8. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
                        Tony F.

                        Thanks again Kiran for the additional info. Unfortunately my console.log messages do not appear in my success option.

                         

                        I was just wondering on the following items pls:

                         

                        1) could this be b/c apex.server.process in Oracle APEX 5.1.2 are Asynchronous?

                        2) do I need to use Promises?

                        3) Would it be possible to get access to the backend of your demo app just to see what I am doing compared to your processing?

                         

                        Thanks again.

                         

                        Tony.

                        • 9. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
                          Tony F.

                          Hi,

                           

                          Any updates on this as I can't seem to get the success option working with console.log(data)?

                           

                          Thanks.

                           

                          Tony.

                          • 10. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
                            Mariusz Kremer

                            Tony,

                             

                            Could you check what happens when you replace "success" with "complete"?

                             

                            Mariusz

                            • 11. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
                              swesley_perth

                              Hi Tony,

                               

                              I would look at the success method, and consider using .done() instead.

                              I'm not sure how this may be impacting you now, I'm just about to embark on an upgrade myself.

                               

                              Here is an early play

                              Grassroots Oracle: Synchronous Dynamic Actions in APEX 5.1

                              The german community has a great article from the perspective of dynamic actions

                              https://apex.oracle.com/pls/apex/germancommunities/apexcommunity/tipp/5741/index-en.html

                               

                              Scott

                              • 12. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
                                Tony F.

                                Thanks Scott.

                                 

                                With the .done() method, which relates to JS Promises, I've read that Promises, i.e. .done() is not supported within IE11, which is a requirement (SOE) here at my place of employment.

                                 

                                Is there a workaround for this?

                                 

                                Furthermore, I also tried the .done() in Chrome and even there I wasn't able to get this working. Appreciate your article but do you have a simple example of passing in one page item to an apex.server.process with a .done() as I placed a console.log message and it didn't appear in my console.

                                 

                                Furthermore, do you have an article on how to debug AJAX processes within Oracle APEX as I've tried it with DEBUG on but still can't seem to get this going as my AJAX processing is occurring within a dialog modal screen.

                                 

                                Thanks.

                                 

                                Tony.

                                • 13. Re: apex.server.process Success Function in APEX 5.1.2 - Has something Changed?
                                  swesley_perth

                                  I have this, which mentions your problem with IE11 (info I forgot).

                                  Grassroots Oracle: Calling PL/SQL from JavaScript in APEX

                                  Sound like you're a rock in a hard place, since support for IE11 ended in Jan16.

                                   

                                  I've just had another thought - I'm not sure IE actually recognises console.log

                                  https://stackoverflow.com/questions/22315167/in-ie11-how-to-use-console-log

                                   

                                  So perhaps try confirm with apex.debug() and turn on debug mode.

                                  My bet is you'll have success with this, pun intended, because I can't see how APEX would influence the underlying web mechanics.