Posted by Paul Haag
As you may or may not know, Dynamics 365 for Financials (we’ll just call it Financials as a shorthand for this post) is based on Dynamics NAV, so, although they may diverge eventually, most of the concepts of connecting to Dynamics NAV work right out of the box. In this post, we’re going to take a look at the steps necessary to service-enable the Sales Invoice page and then start creating invoices in a simple command.
|
Enable the Sales Invoice Web Service
In the NAV / Financials world, you have to one-off enable queries or pages for connectivity through web services.
- Navigate to the Web Services page (you can just search for it). You will already see a list of existing Query web services (these are used by the Power BI dashboard integration).
- Click New and enter:
a. Object Type: Page
b. Object ID: search for Sales Invoice.
c. Service Name: SalesInvoices (or similar)
d. Mark Published. - After you save it, the URLs will be populated. In my case, I couldn’t scroll to the right to see all of them, but you can hover over any of the column headers and select Choose Columns to narrow it down.
- Copy the OData URL (not the OData V4 URL) since Visual Studio’s Add Service Reference doesn’t work with V4 yet.
Figure Out your Credentials
When connecting to the Financials' web services, you use a different username and password than when you log in.
- Navigate to the Users page.
- Select your user in the List and click Edit in the ribbon.
- Note the value in your User Name field. That’s your user name for the web services.
- In the ribbon header, click the Change Web Service Key button.
- Either enter a date when the password will expire or mark that it never expires and click Done.
- If it didn’t automatically, expand the Web Service Access area (by clicking on the header) and copy the Web Service Access Key.
Create Invoices!
Now we'll use Visual Studio's native OData client functionality to connect to the web service and create an invoice. I'm using Visual Studio 2015.
- Create a new Console Application project.
- Right-click References and choose Add Service Reference.
- For the address, use everything up until the OData part of your URL. For example, https://mycompany.financials.dynamics.com:7048/MS/OData
- Visual Studio will prompt you for credentials, so enter the User Name and Web Service Access Key you got earlier.
- It should find a Service called NAV (I told you it was based on Dynamics NAV).
- Change the Namespace to whatever you want or leave it as ServiceReference1 and click OK.
- Copy and paste the following code block (be sure to replace the URL and credentials with the correct values):
There are a couple of notes with this:
- The relationships between records (i.e. between the invoice and the customer) are through the Name fields, but you can specify the key values. Above, I have specified Customer No. 20000 for the Sell_to_Customer_Name.
- The Financials web services automatically expose some related collections (i.e. line items for an invoice). You add to those by using the AddRelatedObject method and specifying the “Navigation Property” name.
- To see the metadata for all of the web services (and things like Navigation Properties), add /$metadata to the OData URL you specified when adding the service reference in Visual Studio.
- Note that your company name is appended to the URL to integrate to a specific company. I’m not 100% sure if that can ever be different than what you see in the Business Manager when you log in, but that is what it was for me (URL encode, of course).
Other Tools
Of course, I showed using this with Visual Studio, but these web services are OData- (and OData V4-) compliant, so there are a number of other tools that would work out there. eOne Solutions already has a NAV connector and I’ve been told they’ll be adding a connector specifically for Financials shortly.
If you have any questions feel free to contact us.
If you have any questions feel free to contact us.