5 Replies Latest reply: Jul 14, 2014 12:15 AM by scott.wesley RSS

    How to Set the Value of an ***APPLICATION*** Item with apex.server.process?

    Joe Upshaw

      If I were to have a page item named P1_MY_PAGE_ITEM, I could set its value in the session by doing this:

       

      $s('P1_MY_PAGE_ITEM', 'I Like Pie!');
      
      apex.server.process(   'dummy'
                             , { pageItems: "#P1_MY_PAGE_ITEM" }
                             , { dataType: "text",
                               async: false,
                                 complete: function( ajaxResponse )
                                       {
                                            var ignoredReturn = ajaxResponse.responseText;
                                       }
                               });

      That works just fine. If you check the session, P1_MY_PAGE_ITEM will now have the value: I Like Pie!

       

      However, if I were to have an Application Item (not a page item!) named MY_APP_ITEM, how might I do the same thing? How might  I use apex.server.process to set the value of MY_APP_ITEM in the session? I wouldn't be able to use "pageItems" because MY_APP_ITEM isn't a page item, it's an application item.

       

      What's the correct syntax for doing this?

       

      Thanks,

       

      -Joe

        • 1. Re: How to Set the Value of an ***APPLICATION*** Item with apex.server.process?
          scott.wesley

          I would think you need to call an actual on-demand PL/SQL process and set the application item from there?

           

          :F_APP_ITEM := 'I also like pie';

          • 2. Re: How to Set the Value of an ***APPLICATION*** Item with apex.server.process?
            Tom Petrus

            Hi Joe,

             

            Harkening back to this thread you made a couple of months ago, the answer is in there:

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

             

            Setting an application item is as easy as providing the name of the application item to the p_arg_names array, and set a correspondent value in the p_arg_values array.

            For example, in an application with application item SOME_ITEM, I can set the value like this:

            (function(){
            var arrNames = [], arrValues = [];
            arrNames.push("SOME_ITEM");
            arrValues.push('some value');
            apex.server.process(   'dummy'
                                 , { p_arg_names: arrNames, p_arg_values: arrValues }
                                 , { dataType: "text"
                                   });
            })()
            

             

            No on-demand process required. The item does have to be unrestricted as you're setting it from the browser.

            • 3. Re: How to Set the Value of an ***APPLICATION*** Item with apex.server.process?
              Joe Upshaw

              Well...that was really how to call an APPLICATION Process rather than how to set an Application Item. So, I actually didn't realize you could put in an Application Item name there. Very cool.

               

              Here's my final version for any others out there to whom this might prove useful:

               

              I created an Application Item named READ_ONLY_FLAG and this is how it is being set based on the user clicking a check box (or by user role for read only users...not shown)

              function setGlobalReadOnly(readOnlyFlag)
              {
                var argumentNameArray = [];
                var argumentValueArray = [];
              
                argumentNameArray[0] = 'READ_ONLY_FLAG';
              
                if( readOnlyFlag === true )
                {
                  argumentValueArray[0] = 'Y';    
                }
                else
                {
                  argumentValueArray[0] = 'N';    
                }
              
                apex.server.process(   'dummy'
                                         , { p_arg_names: argumentNameArray, p_arg_values: argumentValueArray }
                                         , { dataType: "text",
                                           async: false,
                                             complete: function( ajaxResponse )
                                                   {
                                                        var ignoredReturn = ajaxResponse.responseText;
                                                   }
                                           });  
              }
              

               

              Thanks, Tom!

               

              -Joe

              • 4. Re: How to Set the Value of an ***APPLICATION*** Item with apex.server.process?
                Joe Upshaw

                Scott,

                 

                Technically, that works and your answer is absolutely correct. However, we need to set the value without submitting the page...that's why we were using the AJAX call.

                 

                Thanks,

                 

                -Joe

                • 5. Re: How to Set the Value of an ***APPLICATION*** Item with apex.server.process?
                  scott.wesley

                  If anyone could have answered this it was Tom - he has a great write up on this type of stuff

                  Tom's Blog: Ajax in Apex: introduction and techniques

                   

                  I was still suggesting you use the AJAX call, just replacing 'dummy' with an AJAX Callback process (on-demand PL/SQL process) where you can run whatever PL/SQL you like.

                   

                  I know there is an overlap with jQuery here, but it seems the apx.server.process documentation could have some more information/examples specific to APEX use cases.

                  JavaScript APIs

                  I'm looking at you, async parameter...