Lock Command and $Test
In ObjectScript, the $Test system variable gets set when the system runs certain commands, such as Lock, when used with a timeout. The value of this variable is either 0 (false) or 1 (true).
You can use a timeout (in seconds) on Lock, so that it doesn't wait forever. If the Lock is unsuccessful in the allotted time, the system sets the $Test variable to 0. You can then check the value of $Test. To try this out, lock a record:
Terminal
USER>lock +^PersonD(1)
USER>
In a different Terminal, try to lock the same record for 5 seconds:
Terminal
USER>lock +^PersonD(1):5
USER>if ('$test) { write "Someone else is editing that record. Try again later." }
Someone else is editing that record. Try again later.
USER>