How to copy existing attachments into a new document?

isabtogumonisabtogumon Member Posts: 49
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

  • lubostlubost Member Posts: 628
    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

  • lubostlubost Member Posts: 628
    Use standard functionality and then you can use COPYLINK method.
  • isabtogumonisabtogumon Member Posts: 49
    Thank you! Could you explain what you mean by "standard functionality"? How does it work with the COPYLINK method?
  • lubostlubost Member Posts: 628
    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.
  • isabtogumonisabtogumon Member Posts: 49
    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
Sign In or Register to comment.