How to copy existing attachments into a new document?

isabtogumon
isabtogumon Member Posts: 50
I have the procedure to duplicate an existing document into a new one, but I am unable to copy the attachments to the new document. I have done some tests, but some attachments are duplicated. What is the way to do this?

OriginalDocAttach.SetRange("Table ID", 38);
OriginalDocAttach.SetRange("No.", OriginalPurchaseOrder."No.");
if OriginalDocAttach.FindFirst() then
repeat
NewDocAttach.Init();
NewDocAttach."Table ID" := OriginalDocAttach."Table ID";
NewDocAttach."No." := NewPurchaseOrder."No.";
NewDocAttach."Attached Date" := OriginalDocAttach."Attached Date";
NewDocAttach."File Name" := OriginalDocAttach."File Name";
NewDocAttach."File Type" := OriginalDocAttach."File Type";
NewDocAttach."File Extension" := OriginalDocAttach."File Extension";
NewDocAttach."Document Reference ID" := OriginalDocAttach."Document Reference ID";
NewDocAttach."Attached By" := OriginalDocAttach."Attached By";
NewDocAttach.User := OriginalDocAttach.User;
NewDocAttach."Document Type" := OriginalDocAttach."Document Type";
NewDocAttach.ID += 1;
NewDocAttach.Insert();
until OriginalDocAttach.Next() = 0;

Best Answer

  • lubost
    lubost Member Posts: 633
    Answer ✓
    Standard functionality uses Record Link table a then you can use ADDLINK, COPYLINKS, REMOVELINK functions.
    If you want use additional fields, you can use additional table to save them and capture events from standard Record Link table to apply your additional data.

Answers

  • lubost
    lubost Member Posts: 633
    Use standard functionality and then you can use COPYLINK method.
  • isabtogumon
    isabtogumon Member Posts: 50
    Thank you! Could you explain what you mean by "standard functionality"? How does it work with the COPYLINK method?
  • lubost
    lubost Member Posts: 633
    Answer ✓
    Standard functionality uses Record Link table a then you can use ADDLINK, COPYLINKS, REMOVELINK functions.
    If you want use additional fields, you can use additional table to save them and capture events from standard Record Link table to apply your additional data.
  • isabtogumon
    isabtogumon Member Posts: 50
    Thank you so much for your suggestion! I replaced all my code with the standard process:
    SourcePurchaseOrder.COPYLINKS(NewPurchaseOrder);  
    
    And it worked perfectly! I appreciate your help