3 Replies Latest reply on Jun 18, 2011 10:42 AM by vee

    How to get global item value using javascript or ajax!!

      Hello !

      How can I read from global(aplication item created in shared components) using ajax or javascript?!
      Lets imagine that I need to get value of that item only by function like:
      function getText() { var itemVal=$x('MY_GLOBAL_ITEM').value;  return itemVal; }
      ....but I connot do it because it is not renderd on page couse it is global item! Soo do somebody know any workaround to do it??
      I know that I can do page item and read value from it , but this is not what I realy need!
      If I have 100 pages and every page need to use my function, it would need 100 items :) - that is why its not good way!

      Please share yours Ideas!

        • 1. Re: How to get global item value using javascript or ajax!!
          Tyson Jouglet

          You have to use a bit of AJAX to fetch an application item value. This solution has three steps. Setting up a callable JavaScript function, Creating an on demand application process and invoking the JavaScript function with a dynamic action.

          1. Setting up a callable JavaScript function:

          This function will call on application level process that has visibility of your application item and then returns the items value.

          Edit your page and past the following JavaScript code into the "Function and Global Variable Declaration" of the your page. You can also add this to the page template you are using but you would also have to wrap this code in script tags.
          getAppItem = function(pItemName){
              var get = new htmldb_Get(null,$v('pFlowId'),'APPLICATION_PROCESS=GET_APP_ITEM',$v('pStepId'));
              gReturn = get.get();
              get = null;
              return gReturn;
          2.Creating an on demand application process:

          The application level process has visibility to your application level item. All it does is retrieve the items value and prints it out the the htp buffer. Essentially this acts as a way to return values to AJAX calls (the javascript function we setup previously);

          go to Shared Components >> Application Processes >> Create.

          Process Point: "On Demand: run this application..."
          Name: GET_APP_ITEM
          Type: PL/SQL Anonymous Block
             -- get the item name passed into the JavaScript function.
             app_item_name varchar2(30) := apex_application.g_x01;
              -- print its value to the buffer
          3. Invoking the JavaScript function with a dynamic action:

          Invoking the function allows you to specify an application level item name and have its value returned. The firing event is specific to what you need but the action needs to be of type execute JavaScript code. In my case Immediately set the value of P1_NUMBER to my application items value. This code does not need to be in a dynamic action but it helps stay organized. you could call it from any script tag.
          Tyson Jouglet
          • 2. Re: How to get global item value using javascript or ajax!!
            Hello Tyson,

            Thanks for great reply post:).

            I used your solution and it's working fine:). The function getAppItem I'm using in event onmouseover and it's getting me expected result.

            I just wondering if I could read this function from static file ~ .js. I've created a static file for example called lib.js with attached getAppItem function inside.

            Next I removed declaration of javascript from header section on my single page couse I need to use function globally.

            I upload my lib.js file to ~SHARED COMPONENTS->STATIC FILES and registered it as #WORKSPACE_IMAGE#.

            Next I've set JavaScript in the page template (mine is One Tab Level...) in header section between
            <script type="text/javascript" src=" #WORKSPACE_IMAGE#lib.js"></script>

            ... and I have no idea why the function it's not fire!

            Thx, Rx
            • 3. Re: How to get global item value using javascript or ajax!!
              the substitution string is "*#WORKSPACE_IMAGES#*" , make sure the file is uploaded to the workspace(static files) without any application selected.

              Also , the js file should not have *<script>* tags
              1 person found this helpful