.netsoapdynamics-nav-2016

Another user has modified the record (NAV webservice)


I'm facing an error which I find very hard to debug.

I have a tool that accesses a Dynamics NAV Page service to create and/or update Customers in our Dynamics NAV database.

50% of the time the tool works just fine, the other 50% it doesn't and it always comes with the same error:

Other user has modified "service_name" "No.=CONST(customer_number)"

The problem is that editing in NAV is disabled, so the only thing that possibly could edit records is the tool itself.

When I search the web i get results like "you try to modify the same record twice" and a bunch of NAV code, but I don't have access to the NAV code, and the NAV consultant we're working with is clueless himself.

If someone somehow could point out possible scenario's that don't involve NAV code that would be awesome.

My workflow is as follows:

  1. I retrieve the records from NAV
  2. I Edit and modify the records where needed
  3. I create and/or update the modified records
  4. Either this succeeds, or I get the error mentioned above

Either way I call the update method only once in this whole process.

Please help me... I am clueless

Kind regards


Solution

  • I had this issue myself recently. I'm not sure which version of NAV it is because I'm not really working with NAV myself, just consuming it's web (soap) service. But I think the issue would be the same in the latest versions as well, since it is not a bug.

    Anyway, as I understand it NAV does this in order to uphold the ACID rules of the database. And in this particular case, NAV is preventing a "dirty write", meaning it is preventing you from updating some data that has been changed into a newer version than the one you have (or say you have).

    This may seem odd for someone who just updated an entity and then wants to update it again, knowing nobody else is using the system or working with the data - but there is a simple reason for this.

    When you update an entity, you provide a value for it's key attribute. This value does NOT just hold a unique identifier for the entity, but also a timestamp or version description if you wish. This means that a key value is a "one shot" thing - you can't use it more than once if you are changing the state of entity.

    So when you update en entity with the key "abcdefg" (just a sample) it is successful. But the next time (maybe 5 seconds later) you want to update the entity and use the same key "abcdefg" it will fail with 100% certainty.

    So how to fix this, well it's simple because the Update method takes the entity to update as a reference (ref) argument, so once the entity is successfully updated, it will have a new value in it's key attribute and this is the current state of the entity - use this value for the next update and so forth.

    This doesn't mean that you always have to retrieve an entity first if you want to update it. The service has a method for checking if it is necessary.

    service.IsUpdated(obj.Key);
    

    If this returns false, you can go ahead and update the entity using the key value you have, if true, then you need to retrieve a new copy because the entity state described in your key is out-dated.

    Hope that made sense and will help others in the same situation that I and the OP were in :)