Hi all, I have a flag that gets added to my main data table when someone has a record open to alert another user that the record is currently in use. To add the initial flag I use the below code in the Window Manager (WindowManager)/Init Procedure()/Code/Priority 7500 (after the files have been opened).
APP:Status = 1 ! = open for editing
APP:StatusUserId = SI.GetUserName () ! ValuesSystemInformationCode (ABC Free)
Once the user closes the record I had the below code in the Window Manager (WindowManager)/Kill Procedure//Priority 5000.
If ThisWindow.Request <> InsertRecord ! added so as to not get An error (Record not Available (33)….
If LocStatusClear = 0
APP:Status = 0 ! = open for editing! Kill the record lock now that the edit is finished
APP:StatusUserId = ''
The above all works as I want it to create the initial flag and clear the flag when exiting etc.
The Issue is…
When a user opens an existing record the flag is applied as expected. When the ?Cancel button is pressed they get the expected message “Are you sure you want to cancel?", they press yes. The flag is cleared as required, but the issue is if the user had made a change to the record it is also now being saved, when they don’t want it being saved.
Any pointers how I can achieve just the file flag being updated on a cancel and no other fields also being saved.
Perhaps a wrapper around the update form would be simplest?
e.g. here’s some pseudo code
CallMyUpdateForm Procedure !Use this as the update form from the browse itself.
!yada yada you can't edit this now because it's in use
If SetMyFlag(TRUE) = FALSE
If SetMyFlag(FALSE) <> FALSE
Message(Error: Can't restore flag)
On Cancel, re-read the record before clearing the flag, then call the normal update. OnCloseEventCancelled() might be useful, but I have not used that before. If you do it in Kill(), then you need to compare the read to the (automatically) saved record and if different throw an error, otherwise you could overwrite somone else’s saved change. (Normal update does this automatically.)
For a normal Update, clear the flag field before the update is done. ThisWindow.SaveOnChangeAction, before the parent call, might be a useful place.
Note that other ways are not thread-safe. And this might still get the “Changed by other station” error (rarely). Another user can get in between your statements…