web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

How to lock a record when updating a page

(0) ShareShare
ReportReport
Posted on by 5,136

Is there any way I can lock a record as I get into Card Page?  This way, any changes I make will supercede any changes made by other users, assuming I was the first one to open the page.  Also, how can I error out if the record I am trying to modify was opened first by another user?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Andrey Baludin Profile Picture
    3,941 on at
    RE: How to lock a record when updating a page

    1. Create a new field "LockerID" in your table

    2. Put

       LockerID := USERID;

       Modify;

    In OnOpenPage trigger

    3.  Put

       LockerID := '';

       Modify;

    in OnClosePage trigger

    4. Put

    if LockerID <> USERID then

      TESTFIELD(LockerID, '');

    in OnModify trigger in your table

  • Suggested answer
    RockwithNav Profile Picture
    8,417 Super User 2025 Season 2 on at
    RE: How to lock a record when updating a page

    Seems to be a nice approach as mentioned by above just in the last one

    if LockerID <> USERID then

     TESTFIELD(LockerID, '');

    I will put some realistic custom Error instead of the error that will be self generated by TESTFIELD Command.

  • Andrey Baludin Profile Picture
    3,941 on at
    RE: How to lock a record when updating a page

    Yes, testfield exception is totally not user-friendly. Error is better.

    But with using error it should be like this:

    If (LockerID <> USERID) AND (LockerID <> '') then

    ERROR('Record is locked');

    In 2017 and 2018 NAV you also could create some magic:

    if LockerID <> USERID then begin

     LockNotification.MESSAGE('Record is locked');

     LockNotification.SCOPE:=NOTIFICATION::LocalScope;

     LockNotification.SEND;

    end;

    Where LockNotification is variable with type = notification

    Notifications are most user-friendly way to inform.

  • Suggested answer
    RockwithNav Profile Picture
    8,417 Super User 2025 Season 2 on at
    RE: How to lock a record when updating a page

    Still thinking why you are adding this with AND Operator

    If (LockerID <> USERID) AND (LockerID <> '') then

    LockerID will never be blank because you already wrote this code on OnOpen Page trigger

    2. Put

      LockerID := USERID;

      Modify;

    In OnOpenPage trigger

  • mbr Profile Picture
    5,136 on at
    RE: How to lock a record when updating a page

    Thank you much Andrey! I used your tactic and just tweaked it a little to work for us!  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
Alexander Ermakov Profile Picture

Alexander Ermakov 2

#2
SC666 Profile Picture

SC666 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans