I have here an example where Het( LastError ) is not functioning the way it should.
I want to check if the "Import Records"-step went ok but I get an error of the "Delete All Records"-script step: "Command is unavailiable..." because there was no record to delete.
Filemaker should reset this LastError before continuing with the next script step.
I see the error appear in the Script Debugger so I'm sure the error comes from the "Delete All Records"-step
Very good tip!
I made the test and it worked well.
But: after deleting the extra script lines, and getting back to the original situation, it also worked well !!??
It doesn't make me feel good, the idea that I can't trust the command Get ( LastError )
Thanks for you reply!
I wonder if it's more a display issue.
Please keep the Set Variable lines in.
They don't cost much and help debugging. And you may want to add some If there to handle the failures.
When it shows up at working speed (not step by step) then it is a malfunction in the trigger imo.
Anyway it is safer fm detects (wrongly) an error to much than one to few.
Thanks for helping me out!
? This script step suppresses normal alert messages displayed by FileMaker client. In a few places the alerts message is not suppressed (can't recall which one).
Use Get (LastError) immediately after the script step you intend to test; a successful intervening step may clear the error code you were intending to capture. See FileMaker error codes.
Have you try getting the last error right after Delete All Records to see if it catches the error ?
Right after Show All Records, you may call Get(FoundCount) and if there are no records skip Delete All Records.
Get(LastError) should be inserted after each script step, even if you do not want to check it. This way the error is reset for the next script step.
Another way to find where the error comes form is to not call Set Error Capture and Get(LastError) and to check in the debugger to stop after an error.
The question is: what does the get ( LastError ) reset?
Is it the first well executed command or is it a Get ( lastError ) command?
Obviously it should be the first. No one is entering a Get ( LastError ) script step after EVERY script step...
BTW, my problem was not finding a solution, which is very easy, but express the weird behaviour of and my lack of trust in the Get ( LastError ) script step.
Well, the problem may be that you run somewhere a calculation triggered by what you do and that may set a new last error state. And that may also be a plugin or a calculation triggered by hotkey, which evaluates something.
that is why we usually put the last error right in a variable after a script step.
Get( LastError ) returns the exit status of the last script step. This means it is extremely volatile, it isn't storing the last non-zero exit status. It is only storing the last exit status.
Set Field [ 'quantity' , 12 ]
If [ Let ( $error = Get ( LastError ) ; $error ) ]
# only non-zero errors will trigger this block
beep
End If
As I understand it, each script step sets an error result at the end of its execution (0 or other), which can be retrieved by a Get(Last Error) right after the script step.
This means that each script step overwrites the preceding step’s error result.
Some script steps do not modify the Get (LastError) result, or at least not in the expected manner. Loop and End Loop, for example, never modify the Get (LastError) result. If itself never modifies Get (LastError) result. The calculation for the If script step, on the other hand, may modify the Get (LastError) result.
I feel like I'm gonna kick myself for not thinking of one, but what's an example of something you could put in an If[] calculation that would overwrite Get(LastError) ?
If you do not specify a calculation or if the calculation is unsuccessful, it will evaluate as false. Use the Get(LastError) function to capture these errors.
Claris documentation specifies the script steps that don't modify the Get (LastError) result:
The following control script steps do not clear the last error condition reported by FileMaker Pro: If, Else, Else If, End If, Loop, Exit Loop If, End Loop, Exit Script, and Halt Script.