Copying header & lines

dulamandulaman Member Posts: 73
edited 2006-10-26 in Navision Financials
Hello,

I need to copy a record in a form that has a header and some related lines but my code is not working fine: it copies the header very well, but lines are ignored.

Note that "No." is the primary key.

// Copy header

recHeader.INIT;
recHeader.TRANSFERFIELDS(Rec);
TempNum := recHeader."No.";
TempNum := TempNum + '-Copy';
recHeader."No." := TempNum;
recHeader.INSERT(TRUE);

// Copy lines

recLine.SETRANGE("No.", Rec."No.");
IF recLine.FIND('-') THEN
REPEAT
  recLine.INIT;
  recLine.TRANSFERFIELDS(recLine);
  recLine."No." := TempNum;
  recLine.INSERT(TRUE);
UNTIL recLine.NEXT = 0;

MESSAGE('You have created a copy from No. ' + TempNum);
GET(TempNum);
CurrForm.UPDATE(FALSE);


What I'm doing wrong??
-- dulaman
"I don't want to believe. I want to know." (Carl Sagan)

Answers

  • ArhontisArhontis Member Posts: 667
    It is because you use one variable to repeat and to init... :)
    recLine.SETRANGE("No.", Rec."No."); 
    IF recLine.FIND('-') THEN 
    REPEAT 
      recLine2.INIT; 
      recLine2."No." := TempNum;
      recLine2.TRANSFERFIELDS(recLine);
      recLine2.INSERT(TRUE);
    UNTIL recLine.NEXT = 0; 
    
  • ArhontisArhontis Member Posts: 667
    #-o Oops, I shouldn't move the "No." line above transferfields:
      recLine2.INIT; 
      recLine2.TRANSFERFIELDS(recLine,FALSE);
      recLine2."No." := TempNum; 
      recLine2.INSERT(TRUE); 
    
  • dulamandulaman Member Posts: 73
    Thank you very much Arhontis, it's now working fine! =D>



    (BTW, this topic should be in Navision forum, not Navision Financials -- I inserted it here by mistake :oops:)
    -- dulaman
    "I don't want to believe. I want to know." (Carl Sagan)
Sign In or Register to comment.