Modifying records with CHANGECOMPANY returns error

-Christoph-Christoph Member Posts: 7
edited 2014-03-05 in NAV Three Tier
Hi guys,

i have a very annoying problem with synchronizing data to a another company. I just upgraded a database from 2009R2 to 2013R2 which includes several updates between various companys.
All of them seemed to fail, so I wrote some very basic code to check the functionality:
item.GET('466634');
item2.CHANGECOMPANY('Test');
item2 := item;

IF NOT item2.INSERT THEN
  item2.MODIFY;

Guess what? If fails. ](*,)

It returns this error:
Microsoft Dynamics NAV
---------------------------

Another user has modified the record for this Item after you retrieved it from the database.

Enter your changes again in the updated window, or start the interrupted activity again.

Identification fields and values:

No.='466634'
---------------------------
OK
---------------------------


I checked it in the customer environment: ERROR
I checked it in Cronus: ERROR
I tried 2013 without R2 in Crons: ERROR
In 2009R2 it works like a charm..

My 2013R2 system is built 7.10.35800.

I'm really clueless..

Best regards
Christoph

Comments

  • -Christoph-Christoph Member Posts: 7
    I used the sunday for some additional testing:
    Item.LOCKTABLE;
    Item2.LOCKTABLE;
    Item.GET('466634');
    
    Item2.CHANGECOMPANY('Test');
    Item2 := Item;
    
    IF NOT Item2.INSERT THEN
      Item2.MODIFY;
    
    Same error as above.
    Item.LOCKTABLE;
    Item2.LOCKTABLE;
    Item.GET('466634');
    
    Item2.CHANGECOMPANY('Test');
    Item2.TRANSFERFIELDS(Item);
    
    IF NOT Item2.INSERT THEN
      Item2.MODIFY;
    
    Same error as above.

    Item.LOCKTABLE;
    Item2.LOCKTABLE;
    Item.GET('466634');
    
    Item2.CHANGECOMPANY('Test');
    Item2.COPY(Item);
    
    IF NOT Item2.INSERT THEN
      Item2.MODIFY;
    
    Same error as above.

    Item.LOCKTABLE;
    Item2.LOCKTABLE;
    Item.GET('466634');
    
    Item2.CHANGECOMPANY('Test');
    tem2.Description := Item.Description;
    
    IF NOT Item2.INSERT THEN
      Item2.MODIFY;
    
    Works! #-o
    Item.LOCKTABLE;
    Item2.LOCKTABLE;
    Item.GET('466634');
    
    Item2.CHANGECOMPANY('Test');
    Item2.Description := Item.Description;
    Item2."Description 2" := Item."Description 2";
    
    IF NOT Item2.INSERT THEN
      Item2.MODIFY;
    
    Works! #-o
    Item.LOCKTABLE;
    Item2.LOCKTABLE;
    Item.GET('466634');
    
    Item2.CHANGECOMPANY('Test');
    Item2.TRANSFERFIELDS(Item,FALSE);
    
    IF NOT Item2.INSERT THEN
      Item2.MODIFY;
    
    All fields, but the PK.. works :-k
    Item.LOCKTABLE;
    Item2.LOCKTABLE;
    Item.GET('466634');
    
    Item2.CHANGECOMPANY('Test');
    Item2.TRANSFERFIELDS(Item,FALSE);
    Item2."No." := Item."No.";
    
    IF NOT Item2.INSERT THEN
      Item2.MODIFY;
    
    All fields, including the PK, but copied manually.. works as well. [-(


    So I have to update all primary key fields by hand for every synchronization process..
  • JuhaJuha Member Posts: 39
    It looks like it’s the timestamp that gives you the troubles.
    Item2 := Item; and Item2.TRANSFERFIELDS(Item); also copies the timestamp. The MODIFY fails because the timestamp of Item2 doesn’t match the timestamp of the existing record in company Test.
    Transferfields with FALSE doesn’t copy the timestamp so it will not fail.

    I can’t see other solution than the one you already found.

    /Juha
Sign In or Register to comment.