Skip to main content

Prepare users for APEX maintenance

I

It is quite easy to do it within app itself, but you can do it programatically too. Let's say you need to take your application offline. Ideally you want to inform user before and during this maintenance. You can use global notification feature. Default styling is non existing, it is just pure text not even enclosed in DIV/SPAN tag. You probably have to use some HTML tags and CSS to make it pop.

You can set same message (even with html/css/javascript) thru APEX_UTIL.SET_GLOBAL_NOTIFICATION.

DECLARE
    in_app_id           CONSTANT apex_applications.application_id%TYPE      := 700;
    in_message          CONSTANT VARCHAR2(4000)                             := 'SERVER RESTART IN 5 MINUTES';
    --
    v_workspace_id      apex_applications.workspace%TYPE;
BEGIN
    -- setup workspace first
    SELECT a.workspace INTO v_workspace_id
    FROM apex_applications a
    WHERE a.application_id = in_app_id;
    --
    APEX_UTIL.SET_WORKSPACE (
        p_workspace                     => v_workspace_id
    );
    APEX_UTIL.SET_SECURITY_GROUP_ID (
        p_security_group_id             => APEX_UTIL.FIND_SECURITY_GROUP_ID(p_workspace => v_workspace_id)
    );

    -- update global message
    APEX_UTIL.SET_GLOBAL_NOTIFICATION (
        p_application_id                => in_app_id,
        p_global_notification_message   => in_message
    );
    --
    COMMIT;
END;
/


Standard representation is a bit dull. I thought it would look nice show it as page error. So I used a bit Javascript to create error and show it after page loads.

This is the payload I used instead of in_message above. It would be better to put this code into app.js file and just call it as a function.

'<script type="text/javascript">
var show_global_notification = function(evt) {
    apex.message.showErrors([{
        type        : apex.message.TYPE.ERROR,
        location    : ["page"],
        message     : "' || in_message || '",
        unsafe      : false
    }]);
};
if (window.attachEvent) {
    window.attachEvent("onload", show_global_notification);
}
else {
    if (window.onload) {
        var curronload = window.onload;
        var newonload = function(evt) {
            curronload(evt);
            show_global_notification(evt);
        };
        window.onload = newonload;
    }
    else {
        window.onload = show_global_notification;
    }
}
</script>'


Comments