Sales Invoice Report

imurphy
Member Posts: 308
I'm in the middle of writing my first sales invoice report - a modified invoice - and am seeing something I can't explain.
I've taken the standard 206 report and copied it.
I've then added a line to the 'Sales Invoice Header - OnAfterGetRecord' trigger which calls a function.
Before it calls the function I take a look at the 'Sales Invoice Header' variable and can see that the Amount column contains 0. However if I open the Sales Invoice Headers table, the row in question has an amount of 42000. My db only has 3 rows at the moment so I'm not mistaking the row.
Whats going on?
I've taken the standard 206 report and copied it.
I've then added a line to the 'Sales Invoice Header - OnAfterGetRecord' trigger which calls a function.
Before it calls the function I take a look at the 'Sales Invoice Header' variable and can see that the Amount column contains 0. However if I open the Sales Invoice Headers table, the row in question has an amount of 42000. My db only has 3 rows at the moment so I'm not mistaking the row.
Whats going on?
0
Comments
-
Hi Ian,
Amount is a flowfield so you will need to do a calcfields on it first0 -
Ok, there is a calculation trigger associated with the field.. but the record in the db contains a value!
I can understand having to recalculate the amount after some change, but its there.
If you always have to calculate it, why does the field exist at all?0 -
Just realised - stupid of me. Of course its calculating the field when I open table from the object viewer, its not really stored.
Ian0 -
Hi Ian,
Yes Nav calculates flowfields when it's displayed (on forms and reports). If it is not displayed you can use the calcfields command or propery on the dataitem / form.0 -
The amount field on the sales line has the following formula associated with it.
Sum("Sales Line".Amount WHERE (Document Type=FIELD(Document Type),Document No.=FIELD(No.)))
Is there any way of doing something similar from C/AL??
I've been browsing throught he help and nothing especially springs out as likely to do this.0 -
with the Nav functions calcfield and calcsums you can do this.
calcfield(Field,Field2,...,FieldX) you use to calculate a flowfield (before set the filter on fields which are used as Filterfields in flowfieldformula)
calcsums(Field,Field2,...,FieldX) you use to calculate a SumIndexField in a base table to a specific key. Like Quantity on table Item Ledger Entry
regardsDo you make it right, it works too!0 -
I should have explained myself better. I didn't mean how to do a calcfields, I meant how could I do a Sum on a range of rows.
Something like:
MyTotal := Sum("Sales Line".Amount WHERE (Document Type=SalesLine."Document Type"::Order,"Document No."='1234567'));
But the Sum function doesn't exist
At the moment I'm doing this by writing a loop to run through each record and adding up the sum. I'm thinking that if the function exists for use in the column definitions, then maybe it exists for use from C/AL0 -
or maybe I've misunderstood your response completely...
I've done little or nothing with filterfields and flowfields so far.
I'll have to do a little searching on the forum for these keywords and see what I can find.
Thanks0 -
Hi Ian,
The quick answer is to doSalesline.setrange( "document type", SalesLine."Document Type"::Order ); Salesline.setrange( "document no.", '1234567'); if salesline.findfirst then repeat Mytotal += salesline.amount; until salesline.next = 0;
This will alway work whether the amount is calculated in a sumindex field or not. Sumindex fields are an efficent way to calculate values and can be seen in the key of a table. You will be guaranteed that a value used in a flowfield is a sumindex field (or the flowfield will give an error).
Thus in this example you can use this to your advantage. So (as Garak suggests)Salesline.setrange( "document type", SalesLine."Document Type"::Order ); Salesline.setrange( "document no.", '1234567'); salesline.calcsums(amount);
will work.
One thing - you started the post with Sales Invoice Header and are now talking about Sales Line. Sales Line is linked to the Sales header table and the amount field on the sales line table is only calculated when an order, etc is released so be careful.
Hope this clears it up for you.0 -
Thanks dave, got it working - I've spent the last couple of days writing a report that indicates how much of an order has been billed/paid/is waiting to be billed....
Ian0 -
Using the customer ledger entries is the way I would go.
Remaining Amount is a very useful field0 -
Savatage wrote:Using the customer ledger entries is the way I would go.
Remaining Amount is a very useful field0
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