1 2 3 Previous Next 34 Replies Latest reply on May 18, 2018 12:05 PM by Alli Pierre Yotti

    Best way to stop execution and pop-up a message if validation fails.

    TinkerBoy

      Hi all.

       

      We are busy with a POC to see if we will be able to replace our Oracle Workflow system that has been running with a Forms front end for about 18 years. The system still work 100%. We just want to replace the forms front end so that it can run on any platform including mobile.

      So we have been converting one of the processes that is not that complicated to prove that it will work.

       

      We are using Apex 5.1 with the Universal Theme.

       

      The process has a submit screen that does all the validation and once everything is valid then the page will kick off the Oracle Workflow process. This works 100%.

       

      Now I am busy with the approval screen. As you can see there are a couple of buttons at the top that the manager can click. Each one of these buttons have different business rules and validations behind them.

       

      Here is the Oracle Forms page

      approve_workflow.JPG

       

      And here is the same page in the Apex system

       

      approve_apex.JPG

       

      For example If you click a button like Reject, the manager has to give a reason why. This reason is only required on a reject, he can enter a note anyway on any of the other buttons by clicking the notes button that I highlighted and then enter the note before  he makes his selection, but is is only mandatory on Reject. On the forms app we force the user to enter the reason by displaying a error message and then stop execution by firing a "RAISE FORM_TRIGGER_FAILURE;"

       

      reject_note.JPG

       

      Then the form will open a dialog so the manager can enter the reason.

       

      note.JPG

       

      I know how to call a dialog and pass data to and from it so the add the note is not the problem.

       

      dialog.JPG

       

       

      I do all the validation in PL/SQL in an dynamic action. But how do I stop execution of that action so that the page is not submitted or processed further like I do with a RAISE FORM_TRIGGER_FAILURE; if there is something wrong (not just a format of a field or item required validation, the validation can be a lookup of a project code and a lot more, it is complex validations, this is just a sample)

       

      And also how do I popup a message like we do in forms, So that the user will know what to do ?

       

      I have read 2 books so far that are recommended and have looked at a number of tutorial, none show a way to do this. What is the best way to get this working in a similar way to the Forms version.

       

      books.JPG

       

      I am sorry if I left out anything that you need more. I am new in this community. Been using Oracle for 20 years but on the Forms and DB side.

       

      Kind Regards.

        • 1. Re: Best way to stop execution and pop-up a message if validation fails.
          TinkerBoy

          OK so I am looking at Validations on its own. I see now you can select the button it should fire on. I will play a bit with it to see if that will do what I need.

          • 2. Re: Best way to stop execution and pop-up a message if validation fails.
            Pavel_p

            Hi,

            this is exactly what I wanted to write. We have validations that produce nice and user-friendly messages next to the appropriate items, so (mis)using dynamic actions for validation cannot be considered as a right approach. Using DAs generates other (unnecessary) problems that you have to deal with. You can apply a Server-side Condition on your validation, which could be either on Button Press or a myriad of other different kinds of conditions, so I suggest to stick with validations and explore what they offer rather than do things your own way. Also keep in mind that (unlike forms apps) whatever comes from the browsers can be tampered, so you have/should perform some server-side validation anyway. Dynamic action is simply something different than validation.

            When I see your quite complex screen, I would rather expect problems making the APEX form look similar, not making the form logic and behaviour similar.

            Regards,

            Pavel

            • 3. Re: Best way to stop execution and pop-up a message if validation fails.
              TinkerBoy

              Nope. The Validation is not firing if I have Dynamic actions configured on the button. So I am not sure what to do at this point.

              • 4. Re: Best way to stop execution and pop-up a message if validation fails.
                Pavel_p

                I would suggest to delete the DA and create a conditional validation.

                Server-side condition: When Button Pressed and select the Reject button from dropdown menu,

                Validation => Type: Item is NOT NULL and choose the PX_NOTE item.

                This way the validation will check if some notes are entered only if the Reject button was pressed.

                • 5. Re: Best way to stop execution and pop-up a message if validation fails.
                  TinkerBoy

                  Thanks for the feedback.

                  How do I fire the code on that button then if there is no DA ?

                  If the validation is OK then the PL/SQL code on that button should fire. The button calls server side package.procedures that will do a lot of DML and interface with the Workflow Engine.

                  • 6. Re: Best way to stop execution and pop-up a message if validation fails.
                    TinkerBoy

                    OK I found this video but I can not see the code. I seems to be possible what I need.

                     

                    https://www.youtube.com/watch?v=ik_nJB1-fz4&t=177s

                    • 7. Re: Best way to stop execution and pop-up a message if validation fails.
                      Pavel_p

                      Sorry for not watching the video, I just saw the title "Client side validations" which is just enough. Client-side validations in web development is a myth, you cannot mean seriously a "validation" that can be simply deleted if you just hit F12 and from the browser development toolbar delete/modify anything you want. It's possible to somehow "prevalidate" the data and eventually immediately notify the user that there is something wrong, but it cannot be considered as a serious validation and server-side validation must follow. Anything and everything can come from the browser, so the server-side validation must be performed before we process the data. Anyone who claims that client-side validations can be taken seriously is either not concerned about security risks, or does not care about security at all.

                      Now I'll try to clarify some basics that may (or may not) be already clear, so excuse me please if I just repeat already obvious things.

                      In desktop development you perform some sequence of commands when you click some button (no matter if it's called a trigger or onClick event), simply all the required logic is in that block of code, e.g. check if something is empty, if so, then show some notification and eventually do some other stuff and stop execution, otherwise execute some other branch like PL/SQL procedure(s) and then you can decide whether you commit or rollback the entire transaction (APEX is different here because it automatically either commits the entire transaction if there are no errors, otherwise rollback). APEX is a bit different here, you can decide whether you perform just some sequence of dynamic actions of various types, or you can Submit the page (which is the default button action). It means that the engine posts the entire page data to the server and then performs some sequence of processes. If you open the Processing section in the Page Designer, you'll see there clearly what happens and in what order (this is page 7 from Sample DB Application).

                      apex_processing.jpg

                      So you can see there that Validations are executed first (the last one is conditional) and if any of the validations fail, the rest of processing is not executed (you can run the page in debug mode and inspect the debug trace for better understanding of what is happening under the hood). So I suggest to:

                      1) change the Reject button from Defined by Dynamic Action to Submit the page,

                      2) right click the PX_NOTE item (or whatever its name is) and choose Create Validation,

                      3) apply a condition on that validation: Server-side condition: When Button Pressed and select the Reject button from dropdown menu,

                      4) specify the type of validation: Validation => Type: Item is NOT NULL and choose the PX_NOTE item.

                      Please, forget for now about Dynamic action and give it at least a try, this is how validations are meant to be done in APEX.

                      • 8. Re: Best way to stop execution and pop-up a message if validation fails.
                        TinkerBoy

                        OK I did as you stated. I used the More Info button for now.

                         

                        validation.JPG

                         

                        When I click on the button nothing happens if the P2_NOTE field is empty. The page is submitted and goes back to the home page. Not sure if it is something to do with how the page is opened. It is opened with a Automatic Row Fetch Process, not a Auto DML There is no DML to do on the page. All that logic sits in the DB. The only thing from a DML side is the note to add. I wanted to insert that by passing it to the package in the DB. That is why I asked if I do not use a DA how will that code get fired. We are trying to keep the Forms System as is and just add the Apex side. So then we can run the 2 side by side and bring over more processes over time. When all is on the Apex side then we can switch off Forms.

                        • 9. Re: Best way to stop execution and pop-up a message if validation fails.
                          Pavel_p

                          There was clearly some misunderstanding as you have there too conditions (probably I did not express myself clearly enough). In the Server-side condition section keep just that When Button Pressed MORE_INFO one and discard the Item is NOT NULL (the validation will be executed whenever MORE_INFO button is pressed, no other conditions are needed), so the Type should be -Select-, Validation section looks OK.

                          You probably created a page on table using the wizard, but the same way you can generate a form based on a package.procedure. Also it's possible to create a completely custom form and in such a case you can write all the code manually into processes (Processing section ´ => Right-click Create process and invoke the required routine like)

                           

                          package.procedure(:px_item1 , :px_item2 ,:px_item3); --begin and end statements are added automatically
                          
                          • 10. Re: Best way to stop execution and pop-up a message if validation fails.
                            TinkerBoy

                            Still does not fire.

                             

                            valid2.JPG

                             

                            I found these 2 sites APEX Client-Side Validation – HardLikeSoftware

                             

                            and

                             

                            Client Side Validations - Explorer | Award Winning UK Oracle Partner

                             

                            And here is the demo app.

                             

                            https://apex.oracle.com/pls/apex/f?p=107625:8:8681207797888::NO:RP,1::

                             

                            IS seems these methods do Client and server side validation. That is what I want.

                            • 11. Re: Best way to stop execution and pop-up a message if validation fails.
                              Pavel_p

                              It seems that our nice conversation does not lead towards any solution. Please, if you don't have a workspace yet, request for a new one here https://apex.oracle.com/en/ and demonstrate your problem (share developer credentials to your workspace).

                              • 12. Re: Best way to stop execution and pop-up a message if validation fails.
                                Billy~Verreynne

                                Client validation needs to be done via Javascript - and normal JQuery UI type features can be used. For example the lost focus event can be used to validate the value of an item, when the user selects the next item for input, and error message displayed via a UI interface addon such as noty in case a validation error needs to be displayed. This is easily integrated into an APEX theme with some minor customisation.

                                 

                                Server validation is however compulsory - and is fully supported by APEX.

                                • 13. Re: Best way to stop execution and pop-up a message if validation fails.
                                  TinkerBoy

                                  I made this little test app. It has 3 buttons on it and 3 text areas. Each button needs to call different business logic in the database thus it needs to call PL/SQL.

                                  Each button also has different validation. In the test app if you click on button 1 then only reason 1 can not be null, reason 2 can be null. If you click on button 2 then only reason 2 can not be null but 1 can be.

                                  If you click on button 3 then reason 1 and reason 2 can not be null.

                                  The validation on the text areas don't fire as the page is not submitted because I am using DA.

                                   

                                  https://apex.oracle.com/pls/apex/f?p=156025:2

                                   

                                  User: DEV

                                  Password: qwerty

                                  • 14. Re: Best way to stop execution and pop-up a message if validation fails.
                                    Alli Pierre Yotti

                                    Hi,

                                     

                                    APEX Server Validation are not fired when using DA. It hust fire when submit the Page. What you should do is to use the APex client side message to display message to your users when a validation fail

                                     

                                    https://docs.oracle.com/database/apex-5.1/AEAPI/apex-message-namespace.htm#AEAPI-GUID-D15040D1-6B1A-4267-8DF7-B645ED1FDA…

                                     

                                    Can you give credentials?

                                    Worspace:?

                                    username:?

                                    password:?

                                     

                                    We will have a look

                                     

                                     

                                    Thank

                                    1 2 3 Previous Next