This content has been marked as final. Show 9 replies
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.
i thought of doing this ,That would definitely be the wrong thing!!! Do NOT do that.
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 ?
From your other post, I suspect you are trying to run this code:
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).
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 ;
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 ;
semsem wrote:Here is a sample On-Error form-level trigger that issues a unique message for several fields, when they need to be entered:
...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
message 'please fill the empty field'.
is this right to be done
-- 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;
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 ?
the code now is :
if :system.block_status = 'CHANGED'
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 ......................... ?
in on_error trigger , if error_code = 40202 then message "msg"
on error_trigger like steve said ?
and why this or that ? what is the difference , what is the best way ?
Edited by: semsem on Dec 9, 2012 4:11 AM
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
or check if Commit did work
VALIDATE(RECORD_SCOPE); IF FORM_SUCCESS THEN COMMIT_FORM; ... END IF;
COMMIT_FORM; IF :SYSTEM.FORM_STATUS='QUERY' THEN GO_BLOCK('xx'); .. END IF;
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
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.