triggers works fine but I wanted to test what happens in case of errors.
I defined a .p as a write trigger of a table (without CRC)
Within this trigger i added two lines
TRIGGER PROCEDURE FOR WRITE OF...APPLY "Error".
My little test in the procedure editor:
FIND FIRST ... EXCLUSIVE-LOCK.DISPLAY ... // Display a field
DO ON ERROR UNDO, RETRY ON STOP UNDO, RETRY ON QUIT UNDO, RETRY: IF RETRY THEN DO: MESSAGE "error" VIEW-AS ALERT-BOX INFORMATION BUTTONS OK. RETURN. END.
... = "A". // Update a field
MESSAGE "All fine".
The trigger undo the transaction (no update occurs, field doesn't get A) but ON ERROR doesn't react and "All Fine" is displayed.Validate fires the trigger directly and ON ERROR works
What is the trick, that the code will be notified about the UNDO with the old On ERROR style?
Yes, you will need to return error or use structure error handling in the trigger code.
But then in the code that you update the record, note that the record is not written out until the end of its scope, or when when you do something to force validation or release of the record, such as VALIDATE/RELEASE. So in your example, the record will get out of scope at the end of the procedure, outside the DO ON block you have coded.
Try RETURN ERROR or UNDO, THROW NEW AppError().
RETURN ERROR has the same effect, UNDO in secret.
With UNDO, THROW NEW Progress.Lang.AppError("Error",1) the same effect plus getting the Error message AFTER "all fine".
When I try this I don't get the "All fine" message.
ON WRITE OF Customer OVERRIDE DO: RETURN ERROR.END.
FIND FIRST Customer EXCLUSIVE-LOCK.
DO ON ERROR UNDO, RETRY:
IF RETRY THEN DO: MESSAGE "Something went wrong..." VIEW-AS ALERT-BOX. RETURN. END.
ASSIGN Customer.Phone = "test".
MESSAGE "All fine..." VIEW-AS ALERT-BOX.
I wrote with VALIDATE it works but without it doesn't, the update doesn't occur and ON ERROR seems not to work
Fernando, i just identified the same. The trigger is fired after the DO block caused by the FIND.
So, it's normal and my bad, working with headache isn't the best :-)