Search code examples
oracle-apexrefreshpage-refresh

APEX refresh- issue with the page refreshing even before db changes


I created a classic report in apex. It is essentially a simple notification system. The aim of this report is to see active notifications. But I also want the user to be able to close each notification. For this purpose I created a virtual column called 'Close' and made it a link. Each row has an icon of a trash can. When the user presses it, it will update a column in the database from IS_READ= 0 to IS_READ=1. The system works great, however I am having trouble with proper refresh. When I delete a notification, the page refrershes, but it displays the old state, the notification is still there. However, when I refresh the page manually, the notification will disappear. I tried all sorts of refreshing techniques (dynamic actions) and triggers but nothing works correctly. Can you please advise me on how to do a refresh only after the change has happened in the database? Here is an explanation how my page is configured: This is the notification system enter image description here

And this is my Dynamic action to delete (update) the records. The .delete-irrow is a jQuery selector of the trash can icon enter image description here

enter image description here

enter image description here

enter image description here


Solution

  • Change your dynamic action to execute javascript code. Then in your javascript code, use a success callback as follows:

    apex.server.process("PP_UPDATETABLE", {}, {
      success: function(pData) {
        if (pData.success) {
              apex.region('yourregionsstaticid').refresh();
    }
      }
    })
    
    

    Afterwards, the only thing you would need is to create an AJAX Callback process with the name: PP_UPDATETABLE on your page's processing section with the PL/SQL source of:

    begin
        update yourtable
        set column = newvalue
        where id = :YOURIDFROMGRID;
    
        apex_json.open_object;
        apex_json.write('success',true);
        apex_json.close_object;
    exception when others then
        apex_json.open_object;
        apex_json.write('success',false);
        apex_json.close_object;
    end;   
    

    This Ajax Callback makes sure that the region refresh code is only executed after the AJAX procedure you defined is returned successfully. If you want further help or details, I suggest you to create a APEX sample application with the same grid/table etc. and share the link and credentials.