Changecompany does not work

Dennis_Decoene
Dennis_Decoene Member Posts: 123
Hi guys,

I'm puzzled, I made the code below to move data from an old table to a new one. When it comes to the second record, it gives this error:
The xxxx already exists.

Identification fields an values:

No.=''
XXXX of course is the name of the table. "No." is indeed the primary key in that table. but in the original table there is no record with the field No. blank.
It seems that for some reason a blank record is inserting. When I debug this, I see that the transferfields does the job correctly and fills the destination record.
I allso tried putting the changecompany statement before transferfields.
IF recCompany.FINDSET THEN REPEAT
  rec80001.CHANGECOMPANY(recCompany.Name);
  IF rec80001.FINDSET THEN REPEAT
    rec2046881.TRANSFERFIELDS(rec80001,FALSE);
    rec2046881.CHANGECOMPANY(recCompany.Name);
    rec2046881.INSERT;
  UNTIL rec80001.NEXT=0;
  rec80001.DELETEALL;
UNTIL recCompany.NEXT=0;

WTF??? ](*,) I'm using 4.0SP3 on SQL2005.

Answers

  • kriki
    kriki Member, Moderator Posts: 9,135
    Is it possible that rec2046881 has property DataPerCompany=No?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Dennis_Decoene
    Dennis_Decoene Member Posts: 123
    No...

    I've changed my code, without changecompany and it gives the same error.

    I'm baffled. Would there be a problem with the transferfields? I cannot imagine that, Navision uses that in their posting routines...
    //IF recCompany.FINDSET THEN REPEAT 
    //  rec80001.CHANGECOMPANY(recCompany.Name); 
      IF rec80001.FINDSET THEN REPEAT 
        rec2046881.TRANSFERFIELDS(rec80001,FALSE); 
        //rec2046881.CHANGECOMPANY(recCompany.Name); 
        rec2046881.INSERT; 
      UNTIL rec80001.NEXT=0; 
      rec80001.DELETEALL; 
    //UNTIL recCompany.NEXT=0; 
    
  • Dennis_Decoene
    Dennis_Decoene Member Posts: 123
    When I changed the parameter of transferfields to TRUE instead of FALSE, it worked.

    I wanted to keep the same timestamp and such as the original. So I set out using FALSE...
  • kriki
    kriki Member, Moderator Posts: 9,135
    When I changed the parameter of transferfields to TRUE instead of FALSE, it worked.

    I wanted to keep the same timestamp and such as the original. So I set out using FALSE...
    I should have noticed the FALSE directly :oops:
    The timestamp is something internally for SQL for the version-principle of Navision.
    The fact that you put false, didn't transfer the primary-key-fields, so you got the error.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!