March 14, 201312 yr Hi all Is it possible to put together a "locking" script where the system will prevent a user from opening a record should another user be accessing/viewing it at that current time? A simple dialog box denying access and then exiting the script should do - but how would filemaker check to see if another user has the record open?
March 15, 201312 yr If the record is being Edited by another user it is already locked automatically. Not sure about another user simply viewing the record.
March 15, 201312 yr Author If the record is being Edited by another user it is already locked automatically. Not sure about another user simply viewing the record. I didn't know this, but it makes sense. I'm still interested about how I could prompt the other user should they try to edit the same record that another user is modifying. Possible?
March 15, 201312 yr It does so.... They'll get a dialog telling them, and a Try Again button... Or Cancel
March 15, 201312 yr it's very easy to test / simulate this. Pick a record and start editing it (type some text in a field), leave the cursor in that field so that you do not commit. Now from the Window menu open a new window. That will open on the same record. Try to edit the record in the new window. You will see how FM handles a record lock
March 19, 201312 yr Author A quick Google search tells me that the error code returned for a "locked" record is 300. I want to create my own custom error message that fits the theme of the system I have written. How would I incorporate a script that returns my error message rather than the standard FM one? I would also like the message to display which user is using the locked record. I would prefer the record on the layout not even be accessible... if not, then perhaps have a field on the layout that states if the record is locked, and by which user. Is this possible? I would assume the get(lasterror) = 300 function would suffice. When the user clicks the "go to" button to access the record and layout, an IF statement could be run and check to see if the record is locked?
March 19, 201312 yr The script step Open Record/Request explicitly attempts to obtain the record lock. If you try this and receive an error, then either the record is in use or the user does not have the necessary edit privileges for this record. Therefore, you could write your own error message using a Custom Dialog. However, I am not aware of any way to capture the "other" user name when attempting to edit a locked record. It's definitely on my wish list.
March 19, 201312 yr I didn't know this, but it makes sense. I'm still interested about how I could prompt the other user should they try to edit the same record that another user is modifying. Possible? Yes. This thread has become both convoluted and confused. First, please go back an read what Wim said. Second, the Error Code for a record Lock is 301, not 300. If Google said that, it's wrong again. 300 is a file lock, something very different. The original idea as I understood it was to alert a user going to a particular record that someone else was editing the record and for that first user not to try to do the same. If the first user does try, FileMaker will return a default error message. However, you can use the OnRecordLoad event trigger to run a script that checks the lock state of the record and returns a custom dialog advising the user with whatever message you desire. This will fire when the user loads the record. Steven
March 20, 201312 yr Author Hi all First, thanks for your patience and help. Currently, on the Layout Setup panel, under script triggers, I have OnRecordLoad run the following script: Freeze Window If [Get(LastError) = 301 Show Custom Dialog ["Incrementing lock has failed! The record is probably in use by another user."] End If Go to layout [original layout] however, when I run Wim's test, an error isn't captured and I am still allowed to open the record (though FM does still prompt me if I do try to edit the content) even if I do return to the original layout (within the new window) and attempt to access the record again. I have attempted to trigger this script via the OnLayoutEnter script trigger, and to no prevail. Also, I have tried to capture error 304 (layout in use by another user) and it doesn't work either. I'm assuming my script can't be set up correctly? Many thanks again!
March 20, 201312 yr I believe you are missing a Set Error Capture [ON] step at the first of the script. And then you have to do something to force the error such as setting a field to itself. That will, of course, lock the record if it isn't already locked. Steven
March 20, 201312 yr This example from Soliant Consulting shows the use of the Open Record step to test if the record is in use http://www.soliantconsulting.com/blog/2012/08/easy-filemaker-modal-edit-dialogs-full-rollback-support It doesn't tell you who has it locked though. Like @bcooney, I've got that on my wish list too. Brian
March 20, 201312 yr Author I believe you are missing a Set Error Capture [ON] step at the first of the script. And then you have to do something to force the error such as setting a field to itself. That will, of course, lock the record if it isn't already locked. Steven Thank you, Steven. Can you provide an example of forcing the error by setting a field to itself? I'm a little confused by what you mean. @brian rich - will check that out now! Cheers
Create an account or sign in to comment