Accessing Invoice Statistics Via Webservice from .NET


I’ve been developing a middle ware app in to act as a bridge from out rather old MS Access system and NAV. I’ve setup a number of webservies in nav to allow me to pass invoices/ purchase invoice customer etc from the access system to NAV as and when needed in order to keep the two systems in sync.

However I’m struggling to get statistics for purchase orders. I’ve published page 161 “Purchase Statistics” as a web serverice but can’t figure out how to get it to return the statistics for a particular purchase invoice. if anyone has experience in doing this for a sales invoices I’m sure that would work here also.

Below is the code i’m using to test with, which currently results in and error (There is an error in XML document (1, 596) when the readmultiple is called. in any case the code isn’t complete as i do know how to tell it which purchase invoice i want the statistics for. Thanks in advance for help!

Dim purchInvoStatsServ As New PurchaseInvoiceStatisticsService.PurchaseStatistics_Service

purchInvoStatsServ.UseDefaultCredentials = False

purchInvoStatsServ.Credentials = _netcreds

Dim purchInvoStats() As PurchaseInvoiceStatisticsService.PurchaseStatistics

purchInvoStats = purchInvoStatsServ.ReadMultiple(New PurchaseInvoiceStatisticsService.PurchaseStatistics_Filter() {}, Nothing, 1)

Hi Duncan,

Without looking at this particular statistics page, you probably found that their is not a unique key presented on the page. There are many pages that can be exposed, but are useless in actual implementation (also look a page 210 - Resource Unit of Measure). If you did have a unique key to get back information, you would run into another problem in that flow fields are not accessible via page based web services.

My advise would be to write an extension codeunit to the purchase statistics page and have it do a calcfields on the values you want to present in your UI. If they are all decimal fields, you could have the code unit function return an array of values to your middleware. I have successfully coded this but the only problem I have is that if I define a return value to return an array of 5, I get 10 values when calling the web service operation (a pair of values for each value I expected). Still working on this.

For more on writing and using and extension code unit and calling from a web service - see: Walkthrough: Creating a Web Service using Extension Codeunits

Hi Wmstreet,

Thanks for your replay, that explains why I’m not getting anywhere with accessing the statistics via the page. At least I now know not to waste anymore time on that avenue.

Regarding using the code unit, i’m abit stuck primarily as the license we have doesn’t seem to allow me to create codeunits! supposidly we have a code unit free in the license but are not permitted to develope it. does that make any sense to you? I really don’t understand the licensing model very well at all and wasn’t involved in the purchasing of the package.

I just need to check that the total value including vat in is that same after i’ve sent it to nav as the amount entered by the user in Access. i.e after Nav has applied the relevent Vat.