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;
0
Answers
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.
And it worked perfectly! I appreciate your help