Hello to all... there has been a long time since I ask for your help.... and here I am one more time.
After 2 years of working with NAV I am still learning new stuff... INCREDIBLE!
Well I am wondering.. :-k ... Is it posible to
LOCK and
MANTAIN the TABLELOCK on a record (or recordset) from the time a FORM is OPEN.... until it is CLOSE?
I trayed to do the following:
[b]Form - OnOpenForm()[/b]
RESET;
LOCKTABLE;
SETRANGE("Document Type", "Document Type"::Order);
SETRANGE("No.", 'SO123312');
FINDSET(TRUE,TRUE);
But when changing the record with other session, nothing happens.
On the other hand if I do this:
[b]Form - OnOpenForm()[/b]
RESET;
LOCKTABLE;
SETRANGE("Document Type", "Document Type"::Order);
SETRANGE("No.", 'SO123312');
FINDSET(TRUE,TRUE);
REPEAT
UNTIL NEXT <> 0;
The record is LOCK and the tablelock is
MAINTAIN.
If you can give me any hints I´ll be more than gratefull....
Cheers,
MarceloB
.:. Marcelo .:.
Answers
Presumably there are many other triggers after which an automatic COMMIT is performed, like for example the OnAfterGetCurrRecord - trigger or the OnValidate-Trigger of a form's textbox. So you may have no chance to establish a permanent LOCKTABLE while the form is open and the user navigates through it or even does some input...
You seem surprised by this. If you've only been doing this for 2 years, you haven't even scratched the surface. Trust me. I've been working with NAV for 9 years and in this business for over 22 years. The learning NEVER stops.
Now on to your issue....
Are you using SQL or the Native DB? LOCKTABLE behaves differently. What are you trying to accomplish? I know you're trying to lock the table. But why? If the user is only viewing the record, why lock it. Have you considered the impact of that lock on other users/processes.
Now, I am Using SQL Server option, and I MUST Lock the Record that is being used by the User.
So, if you have any clues, I will be more than happy to hear from you...
Regards...
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
Regards,
Use ADO to manage a semaphore record in another table. Since ADO is outside of NAV's transaction control you would not have any issue with the auto or imbedded COMMIT statements. Build functions to manage the semaphore records. If one exist, for another user, then set the form as non-editable.
variables
JustOpened -> boolean
OrigRec -> record, same type as form sourcetable
OnOpenForm
JustOpened := TRUE;
OnAfterGetCurrRecord
IF JustOpened THEN BEGIN
OrigRec := Rec;
JustOpened := FALSE;
END;
GET(OrigRec."No.");
LOCKTABLE;
Furthermore it seems to be that there are no transactions or LOCKTABLEs possible within the OnAfterGetCurrRecord trigger at all.
Nope, never tried this code. Just did though and you're right. If you take away the LOCKTABLE statement the rest of the code will lock you on a specific record. I guess you could then use another table/field to maintain a "LOCK" on this record.
The other problem, what Marcelo_B meant, is to open a (card) form with an arbitrary record and as long as the user is "on" that record (as long as the record is visible in the card form) no other user should be able to make any changes to that record. The record should be "locked" for that user in the sense of the LOCKTABLE function of NAV.
gerdhuebner you are right, that was my dilemma... so, as no "record level locking" solution came across, I decided to use a COLUMN as a Semaphore (flag). And so far everything works like a charm.
Thank you... and many thanks to everybody you have been very helpfull.
My Best Regards to all.