Search This Blog

Tuesday, October 11, 2022

Real Time Notification in Oracle Apex Using Ajax Callback Process.

Run time notification in oracle apex. Here it shows only one page. But you can do it globally for getting notifications from any page. 

1. Create a Table For Notification

 CREATE TABLE "NOTIFICATION_TABLE"  

 ( "PID" NUMBER, 

 "MESSAGE" VARCHAR2(30),

 "SEEN_TIME" TIMESTAMP (6), 

 "SEEN_TYPE" VARCHAR2(1)

 )

2. Put the function into the Notification page>> Function and Global Variable Declaration

(function loop(i) {

   setTimeout(function() { 

       apex.server.process ( 

          'AJAX_NOTIFICATION_CALL',

          {}, // params

          {

              async     : true,

              dataType  : 'json',

              success   : function(data) {

                 if (data.MESSAGE) {

                     if (data.SEEN_TYPE == 'N') { 

                      apex.message.showPageSuccess(data.MESSAGE);

                     }

                 }

             }

          }

       ); 

       loop(i);

   }, 4000); // 4sec forever

})();


3. Create an Ajax Call back process and put the below code into this process. Finally, Remane the process name as AJAX_NOTIFICATION_CALL.

BEGIN

       APEX_JSON.OPEN_OBJECT();

       FOR c IN (

           SELECT * FROM NOTIFICATION_TABLE WHERE SEEN_TIME IS NULL ORDER BY PID 

           FETCH FIRST 1 ROWS ONLY

       ) LOOP

           APEX_JSON.WRITE('MESSAGE', c.MESSAGE);

           APEX_JSON.WRITE('SEEN_TYPE', c.SEEN_TYPE);

           UPDATE NOTIFICATION_TABLE

           SET SEEN_TIME = LOCALTIMESTAMP,

                SEEN_TYPE = 'Y'

           WHERE PID = c.PID; 

       END LOOP;

       APEX_JSON.CLOSE_OBJECT();

    END;

4. Finally input the value into the NOTIFICATION_TABLE  table from anywhere and check the Notification page without loading. 

No comments:

Post a Comment

PDF to Text Covert by Oracle Apex

Here are the steps to convert and get the character into a region by Oracle Apex. Step1.  Create a page and Copy-Pest the below code into Pa...