In November of 2008 I wrote an article about using the NAV 2009 Web Services on Gaspode’s Brain Dump. This article received a lot of comments, showing how much interest this topic generates. Sadly, due to some of the limitations with NAV Web Services at that time, the example did not work as well I would have liked. The update worked for a single record (the first record) but other records did not get updated.
Today I tried the same example with NAV 2009 SP1 and I’m pleased to say it all worked as planned. It’s time to re-vamp the walkthrough with a NAV 2009 SP1 feel. I’m using the NAV 2009 SP1 NZ AU release installed on my local machine using the demo option. For your own system, you will need to replace the company name with one that matches your system.
Start the RoleTailored client and press Ctrl+F3 to activate the page search box and type Web Service.
Click the Web Services option to go straight to the Web Services list place. You can select the option from the drop-down list using the keyboard, but it’s a bit difficult to see what’s selected. Use the cursor-down to move into the drop down box and then move up and down through the list to the option you want. In the previous image, the Web Services list place is selected, use the cursor-right key to select the Departments Page that contains the Web Services option.
Click the New button in the Action Pane and select Object Type=Page, Object ID=21, and Service Name=Customer. Don’t forget to tick the Published field to make the Web Service available.
To check that your Web Service is working, enter http://localhost:7047/DynamicsNAV/WS/CRONUS%20New%20Zealand%20Ltd./Page/Customer in to the address bar of your Internet Explorer. You should see the WSDL for the service (note that your company name is likely to be different to the one I’ve given, but at least you will be able to type the company name in as it appears in NAV and your browser will substitute %20 for the spaces in the company name.
If you don’t see the WSDL as shown previously, you should check that your Microsoft Dynamics NAV Business Web Services service is started.
If you do get the WSDL, copy the URL for the Web Service from your Internet Explorer address bar, you’ll need it later on. Now it’s time to fire up InfoPath.
On the Getting Started page, click the option to Design a Form Template. Click on the Web Service icon as shown and click OK.
Keep the option to Receive and submit data and click Next.
Paste the address you copied previously into the text box and click Next.
Click the ReadMultiple operation as the operation that will be used to provide data to the InfoPath form. Click Next to continue.
You can leave the name of the query as Main query and click Next.
The next screen asks for the location of the Web Service used to submit data. Small images are shown because there’s nothing to see here. Move along. Click Next.
Now you are asked which operation is used to submit data. Select UpdateMultiple and click Next.
On the following screen we need to specify where the list of customers needed for the submit operation will come from. With the Field or group radio button selected, click the Modify button.
Expand the tree control in the Select a Field or Group dialogue and highlight the Customer node as shown. Click OK to continue.
Leave the data connection as Main submit and click Finish.
Hurray we have our Template to design.
Expand the query fields and click and drag the filter group on to the box that says “Drag query fields here” and select the option to add the groups as a repeating table. This way users will be able to add any filter fields to the read command. You can select the properties of these fields and set a default value - for example, Field defaults to No. and Criteria defaults to *. This will ensure you get some records back. You will also need the setSize parameter since this is mandatory for the ReadMultiple operation. Drag this on to the control surface and give it a default of 100. You should have a query section that looks something like this.
Now expand the dataFields node and drag the Customer node on to the fields area of the design surface and once again select Repeating Table as the option. This puts in every field which is way too much so just right click on the table after you have created it and select the properties, then click the Change Binding button. You will see a tree that is expanded to show the customer node, that's fine, just click Next and you'll get on to a dialog where you can remove fields. For a quick way to remove all fields, click in the Columns in table list box and hold down Alt+R until there are no fields left - now you can click on the fields you want and add them. I used No, Name, Address and Phone No. You should re-size the fields so they fit the available space and have a larger Name and Address field. Now it's time to run the form and see what happens. Click the Preview button. When prompted, select the option to connect rather than work offline. Hit the Run Query button and accept the dialog box and you should see something similar to the following.
Now the funny thing is, when I tried this at work, it worked which is why I wanted to update this blog post with the new details. Then when I got home and wrote the post, it did not work. You can imagine how happy this made me (not very). I’m wondering whether I need to be connected to the domain for this to work correctly. I’ll post more if I figure out why the results are intermittent.