Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

How to lock a record when updating a page

Posted on by 5,124

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

  • mbr Profile Picture
    mbr 5,124 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!  

  • Suggested answer
    RockwithNav Profile Picture
    RockwithNav 6,562 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

  • Andrey Baludin Profile Picture
    Andrey Baludin 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
    RockwithNav 6,562 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.

  • Verified answer
    Andrey Baludin Profile Picture
    Andrey Baludin 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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans