NAV 2009 Web Services (Part 1 – the simple fuel app.)

Finally getting around to putting together the bits for my exploration into web services, and more importantly how to consume them using C#.

So what's the plan? Well first I need to create a very simple NAV app. Once this is done we need to create the new page objects before we can expose the relevant objects as web services. Finally we will move onto consuming the web services. This final step cuts write to heart of what my blog is going to chronicle – the journey through my initial learning on C# and how it will interact with NAV in the first instance, before becoming the language which will all need to code in (if the current roadmap is anything to go by!).

So to the very simple application itself. I am simply going to record some data each time I fill up my car with petrol. This is a typical and simple application of which there are hundreds about (not necessarily in NAV), but at least let's keep the concept simple in the beginning. The idea is to setup a Vehicle record, and then to record Fuel Entries each time I refuel. The following are the structures:

Vehicle Table

 Field No. Field Name Data Type Length 1 Vehicle Code 20 2 Description Text 100 3 Average MPG Decimal 4 Average Cost per Litre Decimal

Fuel Entry Table

 Field No. Field Name Data Type Length 1 Entry No. Integer 2 Refuel Date Date 3 Refuel Time Time 4 Trip Mileage Decimal 5 Litres Decimal 6 Cost per Litre (£) Decimal 7 Vehicle Code 20 8 MPG Decimal 9 Total Cost (£) Decimal

In order to investigate the exposure of codeunits as web services I have also create the following codeunit:

Fuel Mgmt. Codeunit

OnRun()

CalculateMPG(MilesParam : Decimal;LitresParam : Decimal) MPG : Decimal

IF LitresParam <> 0 THEN

MPG := MilesParam / (LitresParam * 0.22);

CalculateTotalCost(CostperLitreParam : Decimal;LitresParam : Decimal) TotalPoundCost : Decimal

TotalPoundCost := (CostperLitreParam * LitresParam);

The two functions in this codeunit are called on the validate triggers of the respective fields in the Vehicle table.

To round things off I have created 3 simple forms (which should be self explanatory):

• Vehicle Card
• Vehicle List
• Fuel Entries

As I say, nothing very special about this application from a NAV point of view, but we have to start somewhere.

Next time.... creating the pages to represent the forms. That should expose us to the TIF editor and transformation tool – I have used these a few times already with varied results so hopefully we can look at how these tools may be used.

Comment List
Related
Recommended