10 Replies Latest reply: Feb 26, 2014 6:34 AM by Joe Upshaw RSS

    Issue Setting Application Items within apex.server.process for an ***Application*** Process

    Joe Upshaw

      We've been switching out all of our htmldb_get calls for the preferred (and documented and supported!) apex.server.process method. This has worked well so far for invoking AJAX processes from JavaScript so long as the AJAX process in question has been a *Page* level process. However, when we attempt to consume an *Application* process, it just does not appear to be working.

       

      For the examples below, we have two Application Items named PRS_PRODUCT_PROFILE_ID and PRS_PROFILE_OPERATION. We have an On Demand Application Process (*not* a page process!) named MAINTAIN_PRODUCT_PROFILE_2.

       

      Here is the previous htmldb_get approach (which works fine):

       

      function resynchronizeProductProfile(productProfileID)

      {

          var profileOperation = 'EDIT_PROFILE';

       

          var ajaxRequest = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=MAINTAIN_PRODUCT_PROFILE_2',0);

       

          ajaxRequest.add( 'PRS_PRODUCT_PROFILE_ID', productProfileID );

          ajaxRequest.add( 'PRS_PROFILE_OPERATION', profileOperation );

       

          var resynchronizeResult = ajaxRequest.get();

       

          ajaxRequest = null;

       

          return resynchronizeResult;

      }

       

      Here is the (what I think is the) same call using the new apex.server.process approach:

       

      function resynchronizeProductProfile(productProfileID)

      {

          var resynchronizeResult;

       

          $s( 'PRS_PRODUCT_PROFILE_ID', productProfileID );

          $s( 'PRS_PROFILE_OPERATION', 'EDIT_PROFILE' );

       

          apex.server.process(   'MAINTAIN_PRODUCT_PROFILE_2'

                           , { pageItems: "#PRS_PRODUCT_PROFILE_ID,#PRS_PROFILE_OPERATION" }

                           , { dataType: "text",

                               async: false,

                               complete: function( ajaxResponse )

                                        {                                    

                                          var resynchronizeResult = ajaxResponse.responseText;

                                        }

                             });

       

          return resynchronizeResult;

      }

       

      However, in the new version, the arguments do not appear to be getting set when the MAINTAIN_PRODUCT_PROFILE_2 application process is invoked. PRS_PROFILE_OPERATION, for example, is set to '' although, above, you can see that it is, in fact, hard coded to 'EDIT_PROFILE'

       

      Typically, the call to apex.server.process sets item values both in the page and in the session in one step. This doesn't appear to be happening with Application Items (although it works just fine for Page Items).

       

      What's up with this? Anyone see my error?

       

      Thanks,

       

      -Joe

       

      Message was edited by: Joe Upshaw

        • 1. Re: Issue Setting Application Items within apex.server.process for an ***Application*** Process
          Danny*D201

          you could set session values in the MAINTAIN_PRODUCT_PROFILE_2 process like

           

          :PRS_PRODUCT_PROFILE_ID := PRS_PRODUCT_PROFILE_ID;

          :PRS_PROFILE_OPERATION :='EDIT_PROFILE';

           

          yes, the  ajaxRequest.add() does set session values, don't know why apex.server.process doesn't.

          don't see the problem letting process handle session values where you have the plsql support

          • 2. Re: Issue Setting Application Items within apex.server.process for an ***Application*** Process
            Joe Upshaw

            Danny,

             

            So, that certainly won't work as this: :PRS_PRODUCT_PROFILE_ID := PRS_PRODUCT_PROFILE_ID; is not valid PL/SQL.

             

            It is simply going to bark that PRS_PRODUCT_PROFILE_ID is unidentified.

             

            As to the second argument for 'EDIT_PROFILE', I only included this to show that the value of the application item does not get set. Normally, this, too, would need to be passed in as a (changing) variable.

             

            No problem letting PL/SQL handle the the session values but, not sure how to do this with a PL/SQL application process.

             

            -Joe

            • 3. Re: Issue Setting Application Items within apex.server.process for an ***Application*** Process
              Danny*D201

              Hi Joe,

              by looking at the line ajaxRequest.add( 'PRS_PRODUCT_PROFILE_ID', productProfileID );

              I thought

               

              your MAINTAIN_PRODUCT_PROFILE_2 application process uses a parameter called 'PRS_PRODUCT_PROFILE_ID' at some stage.

              and you want to execute this process and set the value of the application item :PRS_PRODUCT_PROFILE_ID to the 'PRS_PRODUCT_PROFILE_ID' you pass to the application process which holds the value of 'productProfileID', that's how I had the line :PRS_PRODUCT_PROFILE_ID := PRS_PRODUCT_PROFILE_ID thinking PRS_PRODUCT_PROFILE_ID is a local variable and :PRS_PRODUCT_PROFILE_ID is the bonding variable.

               

              Anyhow. my understanding is $s( 'PRS_PRODUCT_PROFILE_ID', productProfileID ); will not set the items session value, $s will set the the display value or for use within javascript just fine.

               

              To set an item value in a applciation process:

              javascript bit

              function resynchronizeProductProfile(productProfileID){

                  var profileOperation = 'EDIT_PROFILE';

                  var ajaxRequest = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=MAINTAIN_PRODUCT_PROFILE_2',0);

                  ajaxRequest.addParam('x01', productProfileID );

                  ajaxRequest.addParam('x02', profileOperation );

                  var resynchronizeResult = ajaxRequest.get();

                  ajaxRequest = null;

                  return resynchronizeResult;

              }

              or if you like the apex server process, something like this?

               

              apex.server.process ( "MAINTAIN_PRODUCT_PROFILE_2", {x01: productProfileID,x02: "EDIT_PROFILE"});


              MAINTAIN_PRODUCT_PROFILE_2 process would look like

              begin
              -- nomal process codes

              --

              :PRS_PRODUCT_PROFILE_ID := apex_application.g_x01;

              :PRS_PROFILE_OPERATION := apex_application.g_x02;

              end;

              • 4. Re: Issue Setting Application Items within apex.server.process for an ***Application*** Process
                Joe Upshaw

                I created a sample of the issue on apex.oracle.com.

                 

                Workspace: ICE_SANDBOX

                User ID: oracle_support

                Password: support


                On the one page app, you will see 4 buttons:

                 

                1. Page Proc - htmldb_get - Calls an AJAX method with htmldb_get on the page using an item on the page
                2. Page Proc - apex.server.proc - Calls an AJAX method with apex.server.process on the page using an item on the page
                3. App Proc - htmldb_get - Calls an AJAX method with htmldb_get on the *application* using an item on the *application*
                4. App Proc - apex.server.proc - Calls an AJAX method with apex.server.process on the *application* using an item on the *application*

                 

                1 - 3 work exactly as expected. Whatever value is entered into the single line edit is sent back. 4 does not work. It is unable to set the value of the application item in the session.

                 

                *NOTE* if you set the value of the application item with a prior call, i.e. from App Proc - htmldb_get, then when you call App Proc - apex.server.pro, it will still display it but, it is merely showing the value that was set by the previous call. Note it never changes no matter what is typed into the box whereas with alll the others, they always reflect the current box contents.

                • 5. Re: Issue Setting Application Items within apex.server.process for an ***Application*** Process
                  Tom Petrus

                  Joe, the credentials do not work: You are not authorized to edit applications

                   

                  But anyhow, it is much like Danny said. What you are trying to make apex.server.process do will not work. The pageItems parameter will go look for those items and add those to the data to be sent to the server. Your application items are no page items, and are not rendered on the page. Hence, jquery can not find them nor set or get their value simply because they are not there. No data will be added to the request because nothing can be found.

                  You can however manually add items to a request by interacting with the argument arrays.

                  // 1 on 1 relation between name and value!

                  var arrNames = [], arrValues = [];

                   

                  arrNames.push("PRS_PRODUCT_PROFILE_ID");

                  arrNames.push("PRS_PROFILE_OPERATION");

                   

                  arrValues.push(productProfileID);

                  arrValues.push(profileOperation );

                   

                      apex.server.process(   'MAINTAIN_PRODUCT_PROFILE_2'

                                       , { p_arg_names: arrNames, p_arg_values: arrValues }

                                       , { dataType: "text",

                                           async: false,

                                           complete: function( ajaxResponse )

                                                    {                                   

                                                      var resynchronizeResult = ajaxResponse.responseText;

                                                    }

                                         });


                  Setting the arrays will not interfere with the internal working of server.process as it will just add pageitems to the end of the arrays, so it is safe to use the pageItems property together with the arrays. Adding values to the arrays is just like calling .add on a htmldb_Get object, which is nothing but a wrapper for this operation.

                  • 6. Re: Issue Setting Application Items within apex.server.process for an ***Application*** Process
                    Joe Upshaw

                    Danny,

                     

                    The entire issue is that it works fine with htmldb_get but, not with the new, recommended, apex.server.process method.

                     

                    -Joe

                    • 7. Re: Issue Setting Application Items within apex.server.process for an ***Application*** Process
                      Joe Upshaw

                      Sorry, Tom.

                       

                      I created another user with Developer access. Please use:

                       

                      User ID: apex_forum

                      Password: forum


                      -Joe

                      • 8. Re: Issue Setting Application Items within apex.server.process for an ***Application*** Process
                        Joe Upshaw

                        Tom,

                         

                        So, I am missing something but, sense that I'm close now.

                         

                        The call to apex.server.process now looks like this (Danny's Approach):

                         

                        function resynchronizeProductProfile(productProfileID)

                        {

                        var resynchronizeResult;

                        var profileOperation = 'EDIT_PROFILE';


                        apex.server.process(   'MAINTAIN_PRODUCT_PROFILE_2'

                                             , { x01: productProfileID, x02: profileOperation }

                                             , { dataType: "text",

                                                 async: false,

                                                 complete: function( ajaxResponse )

                                                          {                                 

                                                            resynchronizeResult = ajaxResponse.responseText;

                                                          }

                                               });

                         

                        return resynchronizeResult;

                        }

                         

                        The APPLICATION PROCESS now looks like this:

                         

                        DECLARE

                         

                            lb_ErrorOccurred        BOOLEAN := FALSE;

                            lb_ProductProfileFound  BOOLEAN := TRUE;

                         

                            ls_ResultMessage    VARCHAR2(512);

                         

                        BEGIN

                         

                            :PRS_PRODUCT_PROFILE_ID := apex_application.g_x01;

                            :PRS_PROFILE_OPERATION := apex_application.g_x02;

                         

                            PRS_MGR.MAINTAIN_PRODUCT_PROFILE( :PRS_PRODUCT_PROFILE_ID,

                                                              lb_ProductProfileFound,

                                                              :PRS_PROFILE_OPERATION,

                                                              ls_ResultMessage,

                                                              lb_ErrorOccurred );                                  

                            HTP.PRN( ls_ResultMessage );

                           

                        END;

                         

                        However, the values for apex_application.g_x01 and apex_application.g_x02 are both NULL. So, it still doesn't appear to be setting these afterall

                         

                        If I use your version with the p_arg_names and p_arg_values, how do I refer to these within the Application process? At the end of the day, I need to get the Application Item values updated in the session. So far, this doesn't seem to be possible without htmldb_get.

                         

                        Thanks,

                         

                        -Joe

                        • 9. Re: Issue Setting Application Items within apex.server.process for an ***Application*** Process
                          Tom Petrus

                          Joe,

                           

                          By using the arrays as I showed you can simply use your application items in the process. This is the exact same as what htmldb_Get does: when you use .add() you provide a key-value pair that will be added to the respective arrays, it's just behind the scenes. By manually adding to the array with apex.server.process you get the exact same behaviour, and apex will set the page/application items matching the value in the p_arg_names array with the value in the p_arg_values array.

                          When you test this in your demo app by setting a value to the page item and then using the 4th button (asp app item), you can see the session state of the application item has changed by inspecting session state of application items through "session" on the developer toolbar. (this is in the "apex ajax samples - forum" app)

                          Sure you could use the scalar parameters x## to provide values to the process, but why would you do the extra hoop? If the application items would be set to restricted, you still get the same result as if they were not, and they are easily manipulated through the ajax call anyway. I added an extra button with an ajax call using x01. I never had any issues with using the scalar parameters.

                          • 10. Re: Issue Setting Application Items within apex.server.process for an ***Application*** Process
                            Joe Upshaw

                            Oh!

                             

                            I completely missed that before. Yes, tested, confirmed, working.

                             

                            Thanks, Tom.