Multiple Purchase Lines in Word Template for Automation

snehalppatel
Member Posts: 34
I am trying to create Word Automation functionality to generate .doc file for Purchase Quote. I am able to get all other fields. But I am bit confused about how to implement the Purchase Lines in the word template. Basically the structure of the Purchase Quote in my word document will be somewhat similar to the one shown below:
Description - Qty - Rate - Amount
Item1 - 1 - 10 - 10
Item2 - 5 - 5 - 25
Now, my question is can i keep only one variable for all the fields and loop it through to export multiple lines in the word file? If not, what is the ideal solution to export multiple lines to word from NAV? I would be grateful, if some code is also posted to guide.
Thanks in Advance.
Description - Qty - Rate - Amount
Item1 - 1 - 10 - 10
Item2 - 5 - 5 - 25
Now, my question is can i keep only one variable for all the fields and loop it through to export multiple lines in the word file? If not, what is the ideal solution to export multiple lines to word from NAV? I would be grateful, if some code is also posted to guide.
Thanks in Advance.
Snehal Kumar Patel
MCTS - Microsoft Dynamics NAV
MCTS - Microsoft Dynamics NAV
0
Answers
-
Hello Friends,
I am able to solve my problem by searching some code to play with objects of Word Template using VBA. I found that I can get template's Table object at run-time and add new Rows in it using automation C/AL code. I am herewith posting the code for others to refer to that solved my problem.
In the code I have used variables as shown below:
wdTable - Automation - 'Microsoft Word 11.0 Object Library'.Table
Counter - Integer
PurchaseLine - Record - Purchase Line
What I wanted to achieve was filling values in the rows of table from Purchase Line table. I have already a table in my Word template with headings "Description", "Qty","UOM","Cost","Amount". Hence, I initialized the variable Counter with value "1". Added a new row to the existing table. I looped through Purchase Lines for a particular Purchase Quote and assigned values of each field to respective cells of the row.wdTable := wdApp.ActiveDocument.Tables.Item(1); Counter := 1; IF PurchaseLine.FIND('-') THEN REPEAT wdRow := wdApp.ActiveDocument.Tables.Item(1).Rows.Add; Counter := Counter + 1; wdTable.Cell(Counter,1).Range.Text := PurchaseLine.Description; wdTable.Cell(Counter,2).Range.Text := FORMAT(PurchaseLine.Quantity); wdTable.Cell(Counter,3).Range.Text := PurchaseLine."Unit of Measure Code"; wdTable.Cell(Counter,4).Range.Text := FORMAT(PurchaseLine."Direct Unit Cost"); wdTable.Cell(Counter,5).Range.Text := FORMAT(PurchaseLine."Line Amount"); UNTIL PurchaseLine.NEXT = 0;
Voilla...I am happySnehal Kumar Patel
MCTS - Microsoft Dynamics NAV0
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