3 Replies Latest reply on May 27, 2013 8:27 PM by Kofi

    Display Alert message using Java Script in Oracle APEX

      Hi All,

      I have a requirement to display an alert message in my application. Below is the description of the issue.

      In My application there are 4 types of approvals. i.e. A, B, C and D. First the approver A logsin to the application and opens the record. There he can see a button 'APPROVE'. When he clicks on it, it will lead to another page called 'SIGNATURE'. This page contains Userid and password. By default the logged in userid will be displayed in non-editable mode. he has to enter his password and click on the button 'OK' to approve. As soon as he clicks on OK button, in the previous page in place of APPROVE the word 'REMOVE' will appear. Because he already approved the record. If the approvers wants, he can remove his approval.

      B and C can provide their approvals parallelly. there is no dependency here.
      Once B and C provides their approvals, D can see APPROVE button in his login.

      Once D approves the record, then approval of the record is completed.
      Till here we have no issues. But the scenario is, Suppose for a record Approvers A,B and C provided their approvals.
      Now D has to approve it. He opened the record and and clicked on the button APPROVE. Now SIGNATURE page appears. here he has to provide his password and click on the button OK to approve it. But he is in SIGNATURE page and did not do anything. Meanwhile Approver A has opened the same record and by mistake he removed his approval. After he removes his approval, then D cannot approve the record. But as the approver D is already in SIGNATURE page, even if there is no approval from A, still the application is allowing the Approver D to approve it.
      Here he should get an alert that the approval of A has been removed, hence he cannot approve now.

      Please let me know how I can add the validation using Java Script.
      Let me know if the requirement is not clear. I have not written any Java Script code so far.

      Please help me.
        • 1. Re: Display Alert message using Java Script in Oracle APEX
          Patrick Wolf-Oracle

          I wouldn't use JavaScript for that. Instead I would change the PL/SQL process of your SIGNATURE page to use something like
          update my_approvals
             set approver_d = :Pxx_USER
           where id         = :Pxxx_PRIMARY_KEY
             and approver_a is not null;
          -- If no record has been updated (because approver_a has revoked his approval) we have to raise an error to the user
          if sql%rowcount = 0 then
              raise_application_error(-20999, 'User A has revoked his approval, final approval not possible');
          end if;
          This will make sure that at submit time the approval_a is still there. If not, the update will fail and a process error message will be displayed to the user.

          Member of the APEX development team
          My Blog: http://www.inside-oracle-apex.com
          APEX Plug-Ins: http://apex.oracle.com/plugins
          Twitter: http://www.twitter.com/patrickwolf
          • 2. Re: Display Alert message using Java Script in Oracle APEX
            Hi Patrick,

            Thanks for your response. Is there a way to write the logic for all the approvals in one onbutton click event?
            Is it better if I write separate logic for each approver?

            Actually my manager prefers the Java Script code for this. As I am a oracle guy, I do not have knowledge on java Script and also I am new to APEX.

            Do you have a Java Script solution for this validation?

            Thanks a lot for your help.
            • 3. Re: Display Alert message using Java Script in Oracle APEX
              Hi 980540 (friendly user name required),
              To your question about writing separate logic for each approver, I'd just write one set of PL/SQL code in the database and use that to control all the approval logic.
              Javascript by itself will not easily write data to the database, so if you did all this logic in javascript, how would you persist the changes the approvers have made? Yes you could further call dynamic actions/application processes, etc but it would be an instance of making a very simple issue unnecessarily complex.
              I'd do what Patrick suggested.