User Tools

Site Tools


Sidebar

Go to GMDHsoftware.com

Video Tutorials

User Guide

1. General Information

2. Starting Up

3. Connecting data

4. Demand and Sales Forecasting

5. Inventory Planning

6. Reference

nav-connection-guide

3.5.4. How to Import Data from Dynamics NAV

Dynamics NAV connection is bi-directional: on one hand, it uses the functionality of the Database connector to import data from the NAV database, on the other hand, it can export purchase orders through NAV web-services created beforehand.

To use the export capability of this connection, you will need a NAV developer license and Microsoft Dynamics NAV 2013 or higher.

Below, we describe:

Imported data

This connector utilizes several predefined SQL-queries which you can customize to meet your needs. Data that is imported by the SQL-queries is described on the Inventory management systems page.

Data import workflow

1. Go to the menu File > New > Dynamics NAV connection. The Dynamics NAV connection dialog appears (see figure below).

2. Enter the LAN name or IP-address of the computer running Dynamics NAV Server in the Server field.

You should allow remote connections to the SQL Server if you connect remotely.

3. Enter the name of your company database into the Database field.

4. Enter the name of your company into the Company name field.

To find out the name of your company:

4.1 Open NAV client.

4.2 Enter 'companies' into the search bar and click on the appeared link (see figure below).

4.3 Double click on the company name in the list of companies. The Edit - Companies dialog appears.

4.4 Copy the name and paste it into the field in the Streamline dialog.

5. Enter the credentials of a SQL Server login having permissions to read data from your database into the Username and Password fields. Streamline requires using only SQL Server logins (not Windows logins). If you don't know how to create one, please learn this guide.

6. Enter or choose the date to start the import from in the Starting date control.

7. Choose the data aggregation period in the Group by control. Streamline automatically aggregates your data in the given periods (days, weeks, or months). For example, if you want to see the forecasts, replenishment plans, and other reports in months, group the data by months.

8. Click OK to start the import.

Import Options

  • The Combine locations option allows you to merge all your locations into a single one. This is useful when your warehouses are located next to each other, so they can be planned as a single aggregated warehouse.
  • The Edit SQL queries opens the Database connection dialog where you can customize default SQL-queries to meet your requirements.

Advanced Options

Advanced options of the dialog allow you to configure exporting capabilities of this connection. To do this:

1. Click the Advanced button of the dialog.

2. Insert the web-service SOAP URL that is used to create purchase orders into the Export purchase orders field. Below, we describe how to create such a web-service and generate this URL.

3. Enter credentials of the Windows account that has permissions to start NAV into the Windows username and Windows password fields.

Creating NAV Web-service Used to Export POs

To complete the steps in this section, you will need a NAV developer license and Microsoft Dynamics NAV 2013 or higher.

This web-service will be used to create purchase orders in NAV and will be based on a NAV codeunit. First, open NAV Development Environment. To create the web-service, you should accomplish the following steps:

Open NAV Database

To open your database:

1. Go to File > Database > Open. Open Database window appears (see figure below).

2. Click the black arrow next to the Server Name field, select your SQL Server from the list and click OK (see figure below).

3. Click the black arrow next to the Database Name field, select your database from the list and click OK (see figure below).

4. Click OK in the Open Database window. The Object Designer window appears (see figure below)

Create a Codeunit

As we said above, our web-service will be based on a codeunit. Codeunit is a container for the programmer's code written in a special NAV language called C/AL. In our case, the codeunit will accept several parameters that describe a purchase order and create a purchase order in NAV.

To create a codeunit:

1. Click on the Codeunit button on the left side of the Object Designer window, and then click the New button. C/AL Editor window appears.

To create a PO, our codeunit will use three functions:

  • CreatePurchaseOrder – creates a PO and returns the newly generated PO number;
  • CreatePurchaseLine – adds a new line into a PO by the given PO number;
  • GetUnitOfMeasure – finds and returns the base unit of measure for the given ItemCode.
Since Streamline operates in the base unit of measure of NAV items, we must export ordered quantities using them, regardless of the Purch. Unit of Measure set for items in the NAV Item Card.

2. The next step is to declare these functions. To do this, click the menu View > C/AL Globals. C/AL Globals window appears. Now, go to the Functions tab of the window and put the functions' names in the list (see figure below).

By default, all created functions are local. You can see that by the “LOCAL” prefix before each function name in the C/AL Editor window (see figure above). A web-service that is based on a codeunit doesn't expose local functions, thus they can't be called by an external application, like Streamline. Despite of that, Streamline will use the CreatePurchaseOrder and CreatePurchaseLine functions to push orders into NAV.

To make these functions exposable, we need to set them as global. To do this:

3.Set the cursor on the line with the function name, click menu View > Properties, and set Local property to No (see figure below).

Do this for the first two functions.

Now, let's specify the declaration of the functions by adding their input and output parameters, and local variables. To do this:

3. Set the cursor on the line with the CreatePurchaseOrder function, and click on the Locals button found on the right of the C/AL Globals window. The C/AL Locals window appears (see figure below).

  • Parameters tab is used to specify input parameters of the function;
  • Return value tab specifies variables that will be returned by the function;
  • Variables tab is used to declare local variables of the function.

3.1. Our CreatePurchaseOrder function will accept three parameters, VendorNo, Location and Delivery Date. To declare them, populate the Parameters tab using the information from the table below.

Name DataType Length
VendorNo Code 20
Location Code 20
DeliveryDate Date

See the result in the figure below.

3.2. Now, let's proceed to the Return value tab. As we said above, our function should return the automatically generated PO number. Let's name this variable as OrderNo. Set its return type to Code. (see figure below).

In the body of the function, we will use a local variable that is linked to the record of the NAV PurchaseHeader table. To declare this variable:

3.3. Go to the Variables tab. Add a variable named PurchaseHeader with DataType of Record. To set the Subtype, click on the black arrow next to the field and choose the 38th line which is Purchase Header (see figures below).

Do the same actions for the CreatePurchaseLine and GetUnitOfMeasure functions using the information from the table below.

Name DataType Subtype Length
CreatePurchaseLine
Parameters
OrderNo Code 10
ItemNo Code 20
ItemVariant Code 20
Location Code 20
Quantity Integer
Variables
PurchaseLine Record Purchase Line
PurchaseHeader Record Purchase Header
NextLineNo Integer
GetUnitOfMeasure
Parameters
ItemNo Code 20
Return Value
UOM Code 10
Variables
Item Record Item

After completing all of this, you should have the functions declarations shown in the figure below.

Now, let’s write the functions' bodies.

4. Set the cursor on the next empty line after the declaration of the CreatePurchaseOrder function and copy-paste the following code:

PurchaseHeader.INIT;
PurchaseHeader.VALIDATE("Document Type",PurchaseHeader."Document Type"::Order);
PurchaseHeader.VALIDATE("Buy-from Vendor No.",VendorNo);
PurchaseHeader.VALIDATE("Location Code", Location);
PurchaseHeader.VALIDATE("Expected Receipt Date", DeliveryDate);
PurchaseHeader.INSERT(TRUE);
EXIT(PurchaseHeader."No.");

5. Add the following body for the CreatePurchaseLine function:

PurchaseLine.RESET;
PurchaseLine.SETRANGE("Document Type",PurchaseHeader."Document Type"::Order);
PurchaseLine.SETRANGE("Document No.",OrderNo);

IF PurchaseLine.FIND('+') THEN
  NextLineNo := PurchaseLine."Line No." + 10000
ELSE
  NextLineNo := 10000;
IF NextLineNo = 10000 THEN

CLEAR(PurchaseLine);
PurchaseLine.INIT;
PurchaseLine."Document Type" := PurchaseHeader."Document Type"::Order;
PurchaseLine."Document No." := OrderNo;
PurchaseLine."Line No." := NextLineNo;
PurchaseLine.INSERT(TRUE);
PurchaseLine.VALIDATE(Type,PurchaseLine.Type::Item);
PurchaseLine.VALIDATE("No.", ItemNo);
PurchaseLine.VALIDATE("Unit of Measure Code", GetUnitOfMeasure(ItemNo) );

IF ItemVariant <> '' THEN
  PurchaseLine.VALIDATE("Variant Code", ItemVariant);
PurchaseLine.VALIDATE("Location Code", Location);
PurchaseLine.VALIDATE(Quantity,Quantity);
PurchaseLine.MODIFY(TRUE);

6. Add the following body for the GetUnitOfMeasure function:

Item.RESET;
IF (Item.GET(ItemNo)) THEN BEGIN
   EXIT( Item."Base Unit of Measure" );
END
You must use the same names for the exposed functions as indicated in this guide in order to everything work properly. All functions' declarations (input parameters, return values, local variables) must be the same (case-sensitive) as it described here if you intend to use the functions' bodies indicated in this guide as they are.

Close the C/AL Editor window. Click Yes when it asks to save the changes.

7. Save your codeunit using the Save As dialog appeared.

7.1 Choose the ID for the codeunit from the range 50,000-99,999. This ID range is reserved for customer-specific objects according to the NAV Developer and IT Help.

7.2. Give the codeunit a name. For example, 'CreatePO'. Ensure that Compiled option is checked (see figure below).

After that, your newly created codeunit will appear in the list (see figure below).

Publish the Web-service

The last step is to publish a web-service based on the created codeunit. To do this:

1. Open NAV Client and type into the search bar 'web services'. Click on the Web services link (see figure below)

2. Click the New button of the Home toolbar. Edit- Web Services window appears (see figure below).

3. Select the Codeunit option for the Object Type column.
4. Enter the ID of the created codeunit or choose it from the list for the Object ID column.
5. Give the web-service a name. It is a good practice to set this name as the codeunit Object Name.
6. Set the checkbox checked in the Published column (see figure below).

After that, NAV will automatically generate an URL for the web-service in the SOAP URL column. This URL is used to call the service by other applications like Streamline.

SOAP services must be enabled for your Dynamics NAV Server instance.

Enabling SOAP Services

1. Open Dynamics NAV Administration.
2. Click on your Dynamics NAV Server instance in the tree on the left.
3. Expand the Soap Services section.
4. Ensure that Enable SOAP Services option is checked (see figure below). If it's not:

4.1. Click the Edit button at the bottom.
4.2. Check the option.
4.3. Click the Save button.
4.4. Restart the server.

Testing the Web-service

No, let's test our web-service. To do this, click on the cell with the URL and then click on the little icon with a globe (see figure below).

NAV opens the URL in your default browser. A top part of the server response is shown in the figure below.


Next: Fishbowl

Download PDF

nav-connection-guide.txt · Last modified: 2020/05/18 10:37 by admin