9 Replies Latest reply: Dec 9, 2012 3:21 PM by Andreas Weiden RSS

    forms messages (field must be entered)

    salute-Salem
      i've got a database block in my form based on "patients" table in my database .
      - there are about three not null columns in the patients table .
      - there is a button to be pressed in order to insert data in the patients table through the block .
      the problem is regarding the "field must be entered" message .

      when i press the button when the block is empty , the form shows that message once ,
      and if i enter a number in the pat_id field , then press the button , the form shows it twice
      or once on the status bar , then twice in a pop up message , which enforce me to press the ok button
      to hide it .

      the message is shown more than one time in some cases , and sure i do not want that to happen.

      i thought of doing this ,

      on-error trigger , and write null if the error code = 40202(the number of the "field must be entered message" .
      right or wrong to do this ?

      but sure i want a message to be shown if the user presses the button while a not null field is empty like
      "please fill the empty field" . how can i do this ?
      i am thinking of ,
      if fieldx or fieldy or fieldz is null
      then
      message 'please fill the empty field'.

      is this right to be done ,

      i know ways to do this task , but i want to know the best way to do it ?

      thanks in advance
        • 1. Re: forms messages (field must be entered)
          MLBrown
          I'm not sure if there is a "best way" because I think that it depends on the situation.

          I definitely don't think changing the ON-ERROR trigger is a good idea.

          In the past, I have changed required fields to not required, but created a validation procedure that I call when the user presses save. In that validation procedure I would do something like you mentioned of checking to see if those fields were null and if they were then display a message and raise form_trigger_failure until they fixed it.
          • 2. Re: forms messages (field must be entered)
            user346369
            i thought of doing this ,

            on-error trigger , and write null if the error code = 40202(the number of the "field must be entered message". right or wrong to do this ?
            That would definitely be the wrong thing!!! Do NOT do that.

            From your other post, I suspect you are trying to run this code:
            DECLARE
              V NUMBER(9) ; 
            BEGIN
              if :system.block_status = 'CHANGED'   THEN
                COMMIT ; 
              END IF ; 
              V := :PATIENTS.PAT_ID ; 
              SET_BLOCK_PROPERTY('INSERTED_PAT',DEFAULT_WHERE,'pat_id='||v) ; 
              GO_BLOCK('INSERTED_PAT') ;
              execute_query ; 
            END ; 
            The Commit; followed by the Go_Block is causing the double messages. Here is what you need to do, (and remove the "V Number" part, since you can fix your where clause in the INSERTED_PAT block).
              If :System.Form_Status = 'CHANGED' then
                Validate(Form_Scope); -- causes all validate triggers to run
                If NOT Form_Success then
                  Raise Form_Trigger_Failure;  -- Stops at the first validation or required field
                End if;
                Commit;
                IF :SYSTEM.FORM_STATUS <> 'QUERY' --Do this after every commit
                OR NOT FORM_SUCCESS  THEN  -- It stops the process if the commit failed.
                  RAISE FORM_TRIGGER_FAILURE;
                End if;
              End if;
              GO_BLOCK('INSERTED_PAT') ;
              execute_query ;
            • 3. Re: forms messages (field must be entered)
              user346369
              semsem wrote:
              ...but sure i want a message to be shown if the user presses the button while a not null field is empty like
              "please fill the empty field" . how can i do this ?
              i am thinking of ,
              if fieldx or fieldy or fieldz is null
              then
              message 'please fill the empty field'.

              is this right to be done
              Here is a sample On-Error form-level trigger that issues a unique message for several fields, when they need to be entered:
              -- On-Error form-level trigger
              DECLARE
                Err_Code NUMBER(5)    := ERROR_CODE;
                ITM      VARCHAR2(60) := :SYSTEM.TRIGGER_ITEM; --Identifies validation error field.
                --- Build the default error message ---
                MSG     VARCHAR2(150)
                          := SUBSTR('   '||ERROR_TYPE||'-'||TO_CHAR(Err_Code)||': '
                                                     ||ERROR_TEXT,1,150);
              BEGIN
                IF Err_Code=40202 THEN -- "field must be entered"
                  -- Change MSG on some required fields --
                  IF ITM = 'MY_BLOCK.COLUMN_1' then       --Change block.column to match your form's names
                    MSG := '  Please fill My Field Name'; --Change message to whatever you like
                  ELSIF ITM = 'MY_BLOCK.COLUMN_2' then
                    MSG := '  Please fill My Other Field Name';
                  END IF;
                END IF;
                ---
                MESSAGE(MSG);
                -- On-Error should raise F_T_F except for these 4 messages:
                IF Err_Code not in (40401,40405,      -- No changes to save/apply
                                    40100,40352) THEN -- At first/last record
                  RAISE FORM_TRIGGER_FAILURE; -- Raise flag so processes will stop.
                End if;
              END;
              • 4. Re: forms messages (field must be entered)
                salute-Salem
                sorry for absence for a long time , thanks a lot steve and thanks to all ,
                but can you tell me what the need of all this code is , if i can do it like what i previously said
                if fieldx is null
                or y is null
                or z is null
                message "enter a value please" . what is the difference here , if the two can do the same task . is there something
                wrong with the code i've mentioned ?

                thanks
                • 5. Re: forms messages (field must be entered)
                  Andreas Weiden
                  Whats the code in your WHEN-BUTTON-PRESSED-trigger?
                  • 6. Re: forms messages (field must be entered)
                    salute-Salem
                    the code now is :

                    go_block('patients') ;
                    if :system.block_status = 'CHANGED'
                         THEN
                         commit ;
                         clear_block ;
                         go_block('inserted_patients') ;
                         execute_query ;
                    end if ;
                    :patients.test_date := sysdate ;

                    but i am not asking about the double message now "field must be entered" ,it is solved now by modifying the code , i am asking about the way to change it to the user :
                    should i do it like so : if fieldx is null or y is null then ......................... ?
                    or
                    in on_error trigger , if error_code = 40202 then message "msg"
                    or
                    on error_trigger like steve said ?

                    and why this or that ? what is the difference , what is the best way ?

                    thanks

                    Edited by: semsem on Dec 9, 2012 4:11 AM
                    • 7. Re: forms messages (field must be entered)
                      Andreas Weiden
                      Whats the difference between the standard forms-text "Field must be entered" and your text "You must enter a value" ?

                      I would go with the forms-standard and do not change it. But of course you can supress that the message is shown more than once.

                      Do a validate before you COMMIT
                      VALIDATE(RECORD_SCOPE);
                      IF FORM_SUCCESS THEN 
                        COMMIT_FORM;
                        ...
                      END IF;
                      or check if Commit did work
                      COMMIT_FORM;
                      IF :SYSTEM.FORM_STATUS='QUERY' THEN
                        GO_BLOCK('xx');
                        ..
                      END IF;
                      • 8. Re: forms messages (field must be entered)
                        salute-Salem
                        forget that the message appears more than once , this problem is solved by modifying the code , but i am
                        talking to you as a senior ,
                        when you want to deal with an error like this , and change the message ,
                        would you do it like :
                        if fieldx is null ,.........
                        or on_error trigger like i said ,
                        or like steve said ?

                        i want to know the way to deal with errors and change their messages ? which one of those mentioned ? or is
                        there another one ?


                        thanks a lot
                        • 9. Re: forms messages (field must be entered)
                          Andreas Weiden
                          My approach would be

                          1. Keep as close to the standard as possible, if you don't really need to change messages, don't.
                          2. If you want to trap errors differently, use the validation-triggers (WHEN-VALIDATE-ITEM for items and WHEN-VALIDATE-RECORD for multi-item-rules)
                          3. If you want to have a generic message-handling which changes message for all items in all forms, use Steve's approach with trapping the error and change the text according to the item,

                          So in your case, if you want to change the error text for one item , i'd make the item non-mandatory, and check in the WHEN-VALIDATE-ITEM if its null and show an appropiate message.