Two users modifying same record NAV2013

airamairam Member Posts: 88
edited 2014-02-26 in NAV Three Tier
Dear All,

I have a client which is having an issue where two users would be accessing the same record and one ends up losing information. Basically the below scenario:

User 1
User 2
Opens Order
Edit Line 1
Opens same order
Go to Line 2
Line 1 updated with User 1’s changes
Modify Line 2 ---Modify Line 2
Go to Line 3 :: Successfully Updated
Go to Line 3 :: ERROR - Another User has modified the record..

The client is requesting that when two users would be accessing the same record (in the above example, both are modifying line 2 concurrently); the users will get a notification that there’s another user modifying the same record.

Do you think the above is possible? I’ve tried keeping the USERID of the user but can’t save it OnAfterGetRecord Trigger :/

Thanks in Advance!

Comments

  • vremeni4vremeni4 Member Posts: 323
    Hi,

    On the sales order Subform (sales lines) the pages are setup with the property "DelayedInsert".
    This basically means when user 1 starts changing the record the record will not be saved until he/she moves to a next line.
    At this stage the system will check what is already in the database if it is not the original record you will get the error message from your post. In more detail
    User 1 opens the line and reads "first line".
    User 1 changes this text into "test".
    In the mean time User 2 changed the line to be ''user 2 line'.
    When User 1 moves to the next line the system will try to save the record, anyhow it will notice that xRec and also REc are different "first line" <> ''user 2 line" and "test"<> ''user 2 line". hence system reports the error message from your post.
    It is just a thought, as I never tried this, but If you check on insert trigger xREc and REc this may provide what you want to achieve.

    If the property "DelayedInsert" is not selected then system behaves differently.
    The record will be saved as soon as the primary key is populated.

    I hope this helps.
  • airamairam Member Posts: 88
    Thanks for the below suggestion, not sure if I understood you completly, but I've already tried changing the 'DelayedInsert' to 'No', but that only works with inserting/modifying of the primary key fields. the problem still lies when the users change the 'Quantity' for example. And the message that another user has modified the record comes up only after both finish editing the line, same as my first post.

    I was more after saving a boolean/usercode in the sales line record (not sure where to put the code though) and then clear the value when the user moves away/to another record. This field will be filled in with 'user1' and when a different user accesses the same record it just pops-up that the record is already being accessed by another user. any suggestions pls?

    Thanks again!
  • arcullarcull Member Posts: 191
    This may be a possible solution: put a new fiels in sales line table, like "Viewed by ID", add code on the subform of sales orders on trigger "OnAfterGetRecord" to track viewing, some pseudo code below
    //...code to clear "Viewed by ID" on other records, complete it!
    
    if "(Viewed by ID" <> userid) and ("Viewed by ID" <> '') then
      message('Current record viewed by user %1',"Viewed by ID");
    
    if SalesLine.get("Document Type","Document No.","Line No.") then begin
      "Viewed by ID" := userid;
      modify;
    end;
    
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    Talk at your customer and explain them that NAV uses optimistic concurrency and why it does that.

    Do not try to change this behaviour, No is a powerfull answer for requests like these.
  • airamairam Member Posts: 88
    thanks again for your suggestion, had already tried that before too :-k but I can't use the modify in the onaftergetrecord as per below:


    Microsoft Dynamics NAV
    A transaction must be started before changes can be made to the database.

    Page Edit - Sales Invoice - ##. must close.
    OK

    :cry:
  • airamairam Member Posts: 88
    edited 2014-03-04
    Thanks Mark,

    I'm not seeing a solution to this.

    Will try to re-explain to them.

    Thanks!
  • vremeni4vremeni4 Member Posts: 323
    Hi,

    I would agree with Mark on this.

    Anyhow there is also another option that would work.
    You create a new Page or Form based on a temporary table.

    When a page or Form is opened you pull data from the table and populate the page or form.
    A user can now change the data in the Page/Form.
    As we use a temporary table the records are separated between users.
    When the page is closed (or you can create a Save button) the system compares the entries in the temporary table with the data in the real table. Additional you save the data in the real table.
    If you see the two records are different, you show an error message or confirmation message, reporting who is going to overwrite changes. You can even create a History table with information at what time the record was updated inserted or changed.

    I hope this helps.
  • airamairam Member Posts: 88
    thanks a lot for your suggestion! I'll explain to the client, but will try the above suggestion if need be.

    Thanks and Regards!
Sign In or Register to comment.