codeunit for sum up the values of Purch inv line

Pradeep_Krishna
Member Posts: 8
Hi Expects,
I have to find the inv amount using Inv line that has been invoiced using the reciept lines.
Can some one help me with the codeunit optimization.
the dataitem i choosed was:
Expanded Data Type Data Source Name Include Caption
1 DataItem Purch. Rcpt. Header <Purch. Rcpt. Header> No
0 Column "Purch. Rcpt. Header"."Buy-from Vendor No." VendorNo No
0 Column "Purch. Rcpt. Header"."No." GrnNo No
0 Column "Purch. Rcpt. Header"."Order No." PoNo No
0 Column "Purch. Rcpt. Header"."Order Date" PoDate No
0 Column "Purch. Rcpt. Header"."Document Date" GrnDate No
1 DataItem Purch. Rcpt. Line <Purch. Rcpt. Line> No
0 Column "Purch. Rcpt. Line".Quantity PoQuantity No
0 Column "Purch. Rcpt. Line"."Direct Unit Cost" * "Purch. Rcpt. Line".Quantity Amount No
0 Column "Purch. Rcpt. Line"."Quantity Invoiced" QtyInv No
1 DataItem Purch. Inv. Header <Purch. Inv. Header> No
0 Column "Purch. Inv. Header"."No." InvoiceNo No
0 Column "Purch. Inv. Header".Amount InvoiceAmount No
1 DataItem G/L Entry <G/L Entry> No
0 Column "G/L Entry".Amount PaymentAmount No
0 Column "G/L Entry"."Posting Date" PaymentDate No
0 Column "G/L Entry"."Document No." paymentDocNo No
Codeunit for this is:
Purch. Inv. Header - OnPreDataItem()
IF "Purch. Inv. Header"."Order No." = '' THEN BEGIN
sumamt := 0;
"Purch. Inv. Line".SETRANGE("Purch. Inv. Line"."Receipt No.","Purch. Rcpt. Line"."Document No.");
IF NOT "Purch. Inv. Line".GET("Purch. Rcpt. Line"."Document No.") THEN BEGIN
IF "Purch. Inv. Line"."Receipt No." = "Purch. Rcpt. Line"."Document No." THEN REPEAT
sumamt := sumamt + "Purch. Inv. Line".Amount;
UNTIL "Purch. Inv. Line".NEXT = 0;
"Purch. Inv. Header".Amount := sumamt;
"Purch. Inv. Header".INSERT;
END;
END;
this shows an error as :
Microsoft Dynamics NAV
The Purch. Inv. Header does not exist. Identification fields and values: No.=''
OK
As i have to sum the values for showing the purchase tracker report I coulnt end up getting the result.
Thanks in advance.
I have to find the inv amount using Inv line that has been invoiced using the reciept lines.
Can some one help me with the codeunit optimization.
the dataitem i choosed was:
Expanded Data Type Data Source Name Include Caption
1 DataItem Purch. Rcpt. Header <Purch. Rcpt. Header> No
0 Column "Purch. Rcpt. Header"."Buy-from Vendor No." VendorNo No
0 Column "Purch. Rcpt. Header"."No." GrnNo No
0 Column "Purch. Rcpt. Header"."Order No." PoNo No
0 Column "Purch. Rcpt. Header"."Order Date" PoDate No
0 Column "Purch. Rcpt. Header"."Document Date" GrnDate No
1 DataItem Purch. Rcpt. Line <Purch. Rcpt. Line> No
0 Column "Purch. Rcpt. Line".Quantity PoQuantity No
0 Column "Purch. Rcpt. Line"."Direct Unit Cost" * "Purch. Rcpt. Line".Quantity Amount No
0 Column "Purch. Rcpt. Line"."Quantity Invoiced" QtyInv No
1 DataItem Purch. Inv. Header <Purch. Inv. Header> No
0 Column "Purch. Inv. Header"."No." InvoiceNo No
0 Column "Purch. Inv. Header".Amount InvoiceAmount No
1 DataItem G/L Entry <G/L Entry> No
0 Column "G/L Entry".Amount PaymentAmount No
0 Column "G/L Entry"."Posting Date" PaymentDate No
0 Column "G/L Entry"."Document No." paymentDocNo No
Codeunit for this is:
Purch. Inv. Header - OnPreDataItem()
IF "Purch. Inv. Header"."Order No." = '' THEN BEGIN
sumamt := 0;
"Purch. Inv. Line".SETRANGE("Purch. Inv. Line"."Receipt No.","Purch. Rcpt. Line"."Document No.");
IF NOT "Purch. Inv. Line".GET("Purch. Rcpt. Line"."Document No.") THEN BEGIN
IF "Purch. Inv. Line"."Receipt No." = "Purch. Rcpt. Line"."Document No." THEN REPEAT
sumamt := sumamt + "Purch. Inv. Line".Amount;
UNTIL "Purch. Inv. Line".NEXT = 0;
"Purch. Inv. Header".Amount := sumamt;
"Purch. Inv. Header".INSERT;
END;
END;
this shows an error as :
Microsoft Dynamics NAV
The Purch. Inv. Header does not exist. Identification fields and values: No.=''
OK
As i have to sum the values for showing the purchase tracker report I coulnt end up getting the result.
Thanks in advance.
0
Answers
-
I don't know what you want to do exactly, but i think following code should work:
IF "Purch. Inv. Header"."Order No." = '' THEN BEGIN "Purch. Inv. Line".Reset; //?? needed? "Purch. Inv. Line".SETRANGE("Purch. Inv. Line"."Receipt No.","Purch. Rcpt. Line"."Document No."); "Purch. Inv. Line".setrange("Receipt No.", "Purch. Rcpt. Line"."Document No."); "Purch. Inv. Line".Calcsums(Amount); //Modify header ?? "Purch. Inv. Header".Amount := "Purch. Inv. Line".Amount; "Purch. Inv. Header".Modify(False); //Or Insert, but primary key has to be different.... //if new record => //"Purch. Inv. Header".Init; //"Purch. Inv Header"."No." := 'No....'; //"Purch. Inv. Header".Amount := "Purch. Inv. Line".Amount; //"Purch. Inv. Header".Insert(False); END;
0
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