How to copy existing attachments into a new document?

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;
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
Best 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.0
Answers
-
Use standard functionality and then you can use COPYLINK method.1
-
Thank you! Could you explain what you mean by "standard functionality"? How does it work with the COPYLINK method?0
-
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.0 -
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 help0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions