The error for the unique validation failure is 504.
If you are not seeing it then your trap for get(lasterror) is probably in the wrong place.
If you want to present your own dialog, use the OnValidate script trigger on the field.
Thanks for supplying the 504 code. I peruse the error codes and apparently missed it.
However, even using OnObjectValidate the script does not work. It just hits the IF
statement, evalutes as false and then after the IF, returns get(LastError) of 0.
I am missing something pretty fundamental here and just can't see it.... grrrrr...
OnObjectValidate trigger fires before validating, so there is no error.
From time to time, taking a glance at the “More like this“ sidebar pays off – there is e.g. this related thread.
In the meantime, try this:
i.e. trigger OnValidation, so you can “enter the game” before it happens, then re-trigger the validation by trying to commit, and capture the resulting error code.
In your screenshot, you use Get(LastError) right after the "set error capture [on]", that script step generates no error so Get(LastError) is always going to be 0.
You have to use Get(LastError) right after the script step that you want to have checked.
user19752 and erolst have already covered that the script's logic when using onValidate is not correct: you can't use Get(LastError) with that trigger. You have to logic to test for a failed validation there.
509 is the error for an invalid entry (like text in a number field,...). Is your field set up to require a value?
It looks like FM is 'determined' to use it's error message even though I have a Onvalidate script to run...? (In my OnValidate script I trap for isempty($error); which never gets looked at.... As you can see, this message happens prior to the OnValidate script. As you can also see, I am confused .... 8-)
You would use the OnValidate event to check if the field is valid INSTEAD of setting that up on the field definition level. So it is either or, not and.
Ah, I see (he said, finally finding the light switch)
I 'got' that it is 'either/or' and taking control from FM works for me.
Thanks for the comment.
BTW, have you thought of publishing a "FM Tips/Tricks and Idosyncracies" book?