First step of your loop is to go to Previous, so Exit After Last won't work because it will 'always' go to Previous and not Last, thus it goes on forever and a force quit becomes necessary.
You need to reconfigure the loop scripting to get around this.
Perhaps make the first step a Go To first and then loop through and Go To Next with an Exit After Last at the bottom of the loop. Make sense?
I tried this. Getting it to go to the first record, scrutinising it then going into the loop. It still went nuts on the script trigger.
I'll try again.
Why loop at all?
Define a self join on your phone number field:
YourTable:: Phone = DupCheck:: Phone (DupCheck is a second Table Occurrence of YourTable)
Your script then becomes:
If [count ( DupCheck:: Phone ) > 1 /* duplicate value detected */]
Show custom value["Duplicate value"]
I've now got to work out why!
Note that you can also set a field option that enforces unique values and use it to pop up a warning message. This can be a much better approach as it enforces this for all layouts were this field might be edited.
I needed to 'commit' the record before carrying on the script
Yes, that would be needed make sure the relationship is updated.
Ummm. I hadn't thought about this.
This appears to be much simpler. Is it safer - why?
More consistent really. If someone opened your file with filemaker 9 or earlier, the script trigger wouldn't fire. If you have a second edit screen where this same issue might occur, you have to set up the trigger all over again...
Good thinking, simpler the better!