Top Banner
Chapter 13: Integration Options 13-1 CHAPTER 13: INTEGRATION OPTIONS Objectives The objectives are: Describe the concepts of Microsoft Dynamics NAV Web Services. Create a codeunit Web service, expose a page and a codeunit Web service and consume them from an external application. Describe the concepts of Microsoft Dynamics NAV ODBC, its requirements, installation and limitations. Use Microsoft Dynamics NAV ODBC. Describe the concepts of C/FRONT, its requirements, installation and limitations. Describe the concepts of OCX, its installation, registration and limitations. Use OCX controls. Describe the concepts of Automation, its requirements, installation and limitations. Create a report with Automation. Introduction Microsoft Dynamics® NAV 2009 offers some integration possibilities by using the following technologies: Web service Microsoft Dynamics® NAV ODBC C/FRONT OCX Automation These integration options have their own pros and cons, and sometimes choosing the best technology, depends on a case by case basis. Microsoft Dynamics NAV 2009 offers Web services support as a new method of interacting programmatically with the system. It can be accessed over a network and enables execution on a remote system. It stands as a widely-used, industry standard, which means it is used by other systems and products across the industry. Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement
42
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Na2009 enus devi_13

Chapter 13: Integration Options

13-1

CHAPTER 13: INTEGRATION OPTIONS Objectives

The objectives are:

• Describe the concepts of Microsoft Dynamics NAV Web Services. • Create a codeunit Web service, expose a page and a codeunit Web

service and consume them from an external application. • Describe the concepts of Microsoft Dynamics NAV ODBC, its

requirements, installation and limitations. • Use Microsoft Dynamics NAV ODBC. • Describe the concepts of C/FRONT, its requirements, installation

and limitations. • Describe the concepts of OCX, its installation, registration and

limitations. • Use OCX controls. • Describe the concepts of Automation, its requirements, installation

and limitations. • Create a report with Automation.

Introduction Microsoft Dynamics® NAV 2009 offers some integration possibilities by using the following technologies:

• Web service • Microsoft Dynamics® NAV ODBC • C/FRONT • OCX • Automation

These integration options have their own pros and cons, and sometimes choosing the best technology, depends on a case by case basis.

Microsoft Dynamics NAV 2009 offers Web services support as a new method of interacting programmatically with the system. It can be accessed over a network and enables execution on a remote system. It stands as a widely-used, industry standard, which means it is used by other systems and products across the industry.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 2: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-2

Web Services Web services are a standardized way for independent software systems to communicate with one another over standard Internet protocols. Web services architecture is designed for dynamic program-to-program interaction.

Many kinds of distributed systems can be implemented in Web services architecture. Examples of distributed systems include synchronous and asynchronous messaging systems, distributed computational clusters, mobile-networked systems, grid systems, and peer-to-peer environments.

The broad spectrum of requirements for program-to-program interactions means that the protocols that are used by Web services are more flexible than Web protocols. However, just as the World Wide Web, Web services also rely on a few specific protocols, such as SOAP .

Microsoft Dynamics NAV 2009 supports Web services, which makes it easy to integrate Microsoft Dynamics NAV with other systems. This is possible with the introduction of Microsoft Dynamics NAV Server.

Web services are designed to facilitate the highly dynamic data interchange that is required in business transactions. Web services, as standardized integration technologies, bring value to businesses by breaking down data silos that are created by proprietary integration options. These proprietary integration technologies make it difficult to obtain information in and out of the different systems.

Web services are described by using machine-readable metadata, which provide a robust development and operational environment. Web service metadata serves several purposes. The metadata is used to describe the message interchange formats that a Web service supports, and the valid message exchange patterns of a service. Metadata is also used to describe the capabilities and requirements of a service.

Web Services Description Language (WSDL), which is an XML-based language for defining Web services, is used to express the interchange formats and message exchange patterns of the Web services

Most major software development environments, such as Microsoft® Visual Studio® 2008, can be used to build applications that use Web services. Moreover, because Web services are XML based, Web services can be built across platforms and programming languages.

Architecture

The Web service integration with Microsoft Dynamics NAV is facilitated through Web service enabled codeunits and pages. External systems read and write data on pages and call codeunits as defined by the common Web service protocols, with correct authentication and authorization. The Web service capabilities in Microsoft Dynamics NAV help customers reap the benefits of a service-oriented architecture (SOA).

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 3: Na2009 enus devi_13

Chapter 13: Integration Options

13-3

Microsoft Dynamics NAV Web services are useful to customers and partners who want to use business logic or use a standard interface to access data from outside Microsoft Dynamics NAV.

FIGURE 13.1 MICROSOFT DYNAMICS NAV WEB SERVICES ARCHITECTURE

There are several simple types of Web services that can be published by Microsoft Dynamics NAV. The types of Web services correspond to the degree of complexity required in the Web service interface. All Web services can run C/AL code and validation triggers.

There are several types of Web service in Microsoft Dynamics NAV 2009:

• The simplest Web service type is developed by using the page object. By using the page object, Microsoft Dynamics NAV constructs a default Web service that has a fixed set of methods. Generally, it corresponds to general data access, such as get and set individual values or retrieve and update lists of values.

• Another Web service type involves including codeunits and the functions from those codeunits in the Web service.

• The last type of Web service includes the ability to pass complex data types by using an XMLport object as a parameter in a codeunit function.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 4: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-4

How Microsoft Dynamics NAV integrates Web services saves the complexity of manually setting up Web service frameworks, such as managing the WSDL descriptions. To publish any type of Microsoft Dynamics NAV Web service (page or codeunit), add it to the Web Service table.

Microsoft Dynamics NAV Web Services Support

Pages and codeunits that are added to the Web Service table in Microsoft Dynamics NAV are immediately published and available for Web service requests over the network.

Consumers of these Web services, which are systems integrating with Microsoft Dynamics NAV, only have to know the network name (or address) of the computer that is running Microsoft Dynamics NAV Server and the names given to the individual pages and codeunits.

For example, with the following configurations:

• Computer name that runs Microsoft Dynamics NAV Service: NAV_Server1

• Web service port: 7047 • Microsoft Dynamics NAV Server instance: DynamicsNAV • Company Name: CRONUS International Ltd. • The published page Web service: MyCustomer

Then the MyCustomer Web service is available at the following URL:

http://Nav_Server1:7047/DynamicsNAV/WS/CRONUS_International_Ltd/Page/MyCustomer (http://nav_server1:7047/DynamicsNAV/WS/CRONUS_International_Ltd/Page/MyCustomer)

Microsoft Dynamics NAV manages Web service requests exactly like it handles requests from end-users. User rights authorization and validation, input data validation, business logic invocation, and concurrency control are all managed in the same manner as requests from a Microsoft Dynamics NAV client.

This guarantees that the integrity of the Microsoft Dynamics NAV data is not compromised by using Web services. It also means that code that validates data or invokes business logic for systems that use the Web services that are provided by Microsoft Dynamics NAV does not have to be replicated.

When writing code for Web services, avoid using any end-user confirmation dialog boxes or message boxes. The code for Web services cannot interact with the client that called the code. It cannot respond to a dialog box or any other client interaction requests. Running code with client interaction causes an exception to be thrown. The exception can be caught and handled, but the Web service task will not be completed.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 5: Na2009 enus devi_13

Chapter 13: Integration Options

13-5

The GUIALLOWED function is a function which is used to check whether the C/AL code is allowed to show any information on the screen. When the code is run from Web services, GUIALLOWED always returns FALSE. This is the same with when the code is run in Microsoft Dynamics NAV Application Server.

Opportunities

Integration with other systems and communicating with different entities outside Microsoft Dynamics NAV is always a challenge in any implementation scenarios.

In most cases, customers have different systems that are running together and not only Microsoft Dynamics NAV. Not only that, they may have to exchange data with entities outside their organization, which may use a different system or even a different platform and operating systems.

Advantages

Web services support in Microsoft Dynamics NAV offers great value and benefits over its predecessors, these are as follows:

• Standard integration method, which takes advantage of developer skill sets. This in turn increases development speed and reduces the cost of implementation.

• Increase return on Microsoft Dynamics NAV investment with the integration of data and business logic. Codes have to be written one time and do not have to be redeveloped because the same codes are run whenever using Web services or using Microsoft Dynamics NAV Client.

• Consistent integration point, which reduces management overhead, because of the same security, validation and business logic as using Web services and Microsoft Dynamics NAV Client.

• It also benefits from all other advantages of Web services as an industry standard.

Suitable Candidates

Web services are suited for communication across platforms and programming language. With Microsoft Dynamics NAV 2009, it is easy to integrate with other systems and benefit from the flexibility that Web services offer.

The following are candidates for Web services:

• Solutions that have to execute business logic or read data from Microsoft Dynamics NAV.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 6: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-6

• Solutions that write data to Microsoft Dynamics NAV and use the system to validate the data by using the existing business logic.

• Solutions that extend Microsoft Dynamics NAV with additional information such as customer information, exchange rates, or product information and have the extension that can be accessed from other systems.

The following are examples of several scenarios that are suited to Web services implementation:

• When a new order is created in the system, a Web service communicates with the shipping companies directly to ensure transportation of the order items, checking prices and availability.

• Integration with exchange rates, ensuring that the system is continuously updated with the latest exchange rates, which provides precise calculations of data.

• Integration with a Web service that retrieves the latest address information when new customers are added to the system to ensure accuracy in data.

• Integration with production planning, CRM, data warehouses, other ERP systems, specialized budgeting, planning or reporting systems, mobile solutions and many more.

Demonstration: Create, Expose and Consume Web Services The following demonstration shows how to:

• Create a simple codeunit. • Register the codeunit Web service and a page Web service and

publish them. • Create console applications and consume these two Web services.

Create a Codeunit Web Service

The following steps show how to create a simple codeunit, with a function to capitalize lowercase input string.

In Microsoft Dynamics NAV Classic client:

1. Click Tools, Object Designer. The Object Designer opens. 2. Click the Codeunit button to open the Codeunit list. 3. Click New. The C/AL Editor opens. 4. Click View, C/AL Globals. The C/AL Global window opens. 5. Click the Functions tab, and type the following:

o Name: Capitalize

6. Click the Locals button. The C/AL Locals window opens.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 7: Na2009 enus devi_13

Chapter 13: Integration Options

13-7

7. In the Parameters tab, type the following: o Name: InputString o DataType: Text o Length: 250

8. Click the Return Value tab, and type the following:

o Name: OutputString o ReturnType: Text o Length: 250

9. Close the C/AL Locals window and then close the C/AL Globals

window. 10. In the Capitalize function, type the following:

OutputString := UPPERCASE(InputString);

11. Save the codeunit by clicking File, Save As. The Save As dialog box opens.

12. Type 90001 in the ID and MyCodeunit in the Name and then click OK.

FIGURE 13.2 THE CODEUNIT

13. Close the C/AL Editor.

Expose the Web Services

After the codeunit is created and saved, register it in the Web Services form and select the Published check box. The following steps show how to register Web services:

In the Object Designer:

1. Click the Form button to open the Form list.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 8: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-8

2. Select form 810, Web Services and then click Run. The Web Services form opens.

3. Type the following:

Object Type Object ID Service Name Codeunit 90001 DemoCU

Page 21 Customer

The first line registers the codeunit Web service that is created in the previous steps. The second line registers a page Web service, in this case the Customer page.

4. Select the Published check box on both lines to publish the Web services.

FIGURE 13.3 THE WEB SERVICES FORM

When the Web service is marked as published in the Web Services form, it is immediately available for requests over the network.

5. Close the Web Services form.

Check the WSDL

Before continuing, it is recommended to check that the Web services that previously published are available. Also, ensure that the Microsoft Dynamics NAV Business Web Services is running. The following steps show how to browse to the WSDL document to ensure that the Web services are available.

1. Start Internet Explorer. 2. In the Address bar, type the following:

http://localhost:7047/DynamicsNAV/WS/CRONUS_International_Ltd/Services

NOTE: This address is based on the name of the computer that is running the Microsoft Dynamics NAV Service and the company that is used. The company

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 9: Na2009 enus devi_13

Chapter 13: Integration Options

13-9

name is case-sensitive. In this case, localhost is used instead of the computer name.

3. The page lists the Web services registered and published in the Expose the Web Services section.

FIGURE 13.4 THE WEB SERVICES LISTED IN INTERNET EXPLORER

4. Close Internet Explorer.

Create a Console Application to Consume the Codeunit Web Service

The codeunit Web service is available. The following steps show how to create a simple console application in Visual Studio to consume the codeunit Web service. These steps start with creating a new project in Visual Studio and then adding a Web Reference for the Web services published from Microsoft Dynamics NAV.

1. Open Visual Studio. 2. Click File, New, and then click Project. The New Project window

opens. 3. Expand the Visual C# node, and select Console Application. 4. Type the following:

o Name: UseDemoCU

5. Click OK. The UseDemoCU project initiates with default files and references.

Add Codeunit Web Service as a Web Reference

The next step is to add the published Web service as a Web reference into the project.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 10: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-10

In Visual Studio:

1. In the Solution Explorer, right-click the References node in the project, and then click Add Service Reference. The Add Service Reference window opens.

2. Click Advanced. The Service Reference Settings window opens. 3. Click Add Web Reference. The Add Web Reference window

opens. 4. Type the following in the URL bar:

http://localhost:7047/DynamicsNAV/WS/CRONUS_International_Ltd/Services

NOTE: This address is the same as the address that is used when checking the WSDL by using Internet Explorer.

5. Click GO. The DemoCU service is displayed together with other services that are available.

FIGURE 13.5 THE ADD WEB REFERENCE WINDOW

6. Click View Service for the DemoCU service and then click Add Reference. The DemoCU service is added as a Web Reference in the project.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 11: Na2009 enus devi_13

Chapter 13: Integration Options

13-11

Type the Code

The following steps show how to create a code to consume the codeunit Web service.

In Visual Studio:

1. On the Program.cs tab, type the following:

using System; using System.Collections.Generic; using System.Text;

namespace UseDemoCU { using localhost; // using the web reference

class Program { static void Main(string[] args) { // Create a new instance of the service. DemoCU ws = new DemoCU();

// Use default credentials for authenticating // against Microsoft Dynamics NAV. ws.UseDefaultCredentials = true; ws.Url = "http://localhost:7047/DynamicsNAV/WS/CRONUS_International_Ltd/Codeunit/DemoCU";

// Declare variables to work with. string InputString =""; string OutputString ="";

Console.WriteLine("Input lowercase sentence, end by [ENTER]"); InputString = Console.ReadLine();

// Call the Microsoft Dynamics NAV codeunit Web service. try { OutputString = ws.Capitalize(InputString); } catch (Exception e) { Console.WriteLine(e.Message.ToString()); } // Write output to the screen. Console.WriteLine("Result: {0}", OutputString);

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 12: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-12

// Keep the console window up until you press ENTER. Console.ReadLine(); } } }

2. Click File, Save All to save all the changes in the project.

FIGURE 13.6 THE CODE IN VISUAL STUDIO

Consume the Codeunit Web Service

The following steps show how to test the console application and consume the codeunit Web service:

In Visual Studio:

1. Click Debug, Start Debugging, or press F5 to run the application in debug mode. The console window opens.

2. Type the following: o this is a lowercase sentence

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 13: Na2009 enus devi_13

Chapter 13: Integration Options

13-13

3. Press ENTER. Now, the console application looks like the following:

FIGURE 13.7 THE CONSOLE APPLICATION RESULT

The input string 'this is a lowercase sentence' is capitalized by using the codeunit Web service that is running on Microsoft Dynamics NAV Service. The result in the output string is 'THIS IS A LOWERCASE SENTENCE.'

4. Press ENTER to close the console window.

Create a Console Application to Consume the Page Web Service

In the Expose the Web Services section, two Web services are exposed and published. The previous sections show how to create a console application to consume the first Web service, which is the codeunit Web service. The next section shows how to create a console application to consume the second Web service, which is the page Web service.

In Visual Studio:

1. Click File, New, and then click Project. The New Project window opens.

2. Expand the Visual C# node, and select Console Application. 3. Type the following:

o Name: UseDemoPage

4. Click OK. The UseDemoPage project initiates with default files and references.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 14: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-14

Add Page Web Service as a Web Reference

The next step is to add the published Web service as a Web reference into the project.

In Visual Studio:

1. Repeat Steps 1 to 5 in the Add Codeunit Web Service as a Web Reference section.

2. Instead of using the DemoCU service, click View Service for the Customer service and then click Add Reference.

FIGURE 13.8 THE CUSTOMER WEB SERVICE DESCRIPTION

Type the Code

The following steps show how to create a code to consume the codeunit Web service.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 15: Na2009 enus devi_13

Chapter 13: Integration Options

13-15

In Visual Studio:

1. On the Program.cs tab, type the following:

using System; using System.Collections.Generic; using System.Text;

namespace UseDemoPage { // import newly generated Web service proxy using localhost;

class Program { static void Main(string[] args) { //create instance of service and setting credentials Customer_Service service = new Customer_Service(); service.UseDefaultCredentials = true; service.Url ="http://localhost:7047/DynamicsNAV/WS/CRONUS_International_Ltd/Page/Customer";

//create instance of customer Customer cust = new Customer(); cust.Name ="Customer New";

//insert customer service.Create(ref cust); PrintCustomer(cust); Msg("The program inserted a new customer, press [ENTER] to continue"); Console.ReadLine();

//create filter for searching for customers List<Customer_Filter> filter = new List<Customer_Filter>(); Customer_Filter nameFilter = new Customer_Filter(); nameFilter.Field = Customer_Fields.Name; nameFilter.Criteria ="C*"; filter.Add(nameFilter);

Msg("List before modification"); PrintCustomerList(service, filter); Console.ReadLine();

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 16: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-16

//modify customer cust.Name = cust.Name + " and Modified"; service.Update(ref cust); PrintCustomer(cust); Msg("The program modified the new customer name, press [ENTER] to continue"); Console.ReadLine();

Msg("List after modification"); PrintCustomerList(service, filter); Console.ReadLine();

//delete customer service.Delete(cust.Key);

Msg("List after deletion"); PrintCustomerList(service, filter); Console.ReadLine();

Msg("Press [ENTER] to exit program!"); Console.ReadLine(); }

static void PrintCustomerList(Customer_Service service, List<Customer_Filter> filter) { Msg("Printing Customer List");

//conduct the actual search Customer[] list = service.ReadMultiple(filter.ToArray(), null, 100); foreach (Customer c in list) { PrintCustomer(c); } Msg("End of List, press [ENTER] to continue"); }

static void PrintCustomer(Customer c) { Console.WriteLine("No: {0} Name: {1}", c.No, c.Name); }

static void Msg(string msg) { Console.WriteLine(msg); } } }

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 17: Na2009 enus devi_13

Chapter 13: Integration Options

13-17

2. Click File, Save All to save all the changes in the project.

FIGURE 13.9 THE CODE IN VISUAL STUDIO

Consume the Page Web Service

The following steps show how to test the console application and consume the page Web service:

In Visual Studio:

1. Click Debug, Start Debugging, or press F5 to run the application in debug mode. The console window opens.

The application inserts a new customer named Customer New with the default Customer No.

2. Press ENTER to continue.

The application prints a list of customers, which name starts with the letter C.

3. Press ENTER to continue.

The application modifies the new customer name to Customer New and Modified.

4. Press ENTER to continue.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 18: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-18

The application prints a customer list, which name starts with the letter C, after modification.

5. Press ENTER to continue.

The application deletes the new customer and prints a customer list, which name starts with the letter C, after deletion.

FIGURE 13.10 THE CONSOLE APPLICATION RESULT

6. Press ENTER to close the console window.

ODBC Microsoft Dynamics NAV ODBC is Microsoft Dynamics NAV's implementation of Open Database Connectivity (ODBC). Microsoft Dynamics NAV ODBC lets developers transfer data between Microsoft Dynamics NAV databases and any program that supports ODBC. Applications that support ODBC can communicate with Microsoft Dynamics NAV. This means, applications such as a spreadsheet or word processor can retrieve data by communicating with Microsoft Dynamics NAV through the Microsoft Dynamics NAV ODBC driver.

The Microsoft Dynamics NAV ODBC driver operates in the Microsoft Windows® platforms. In these environments, it can function either as a stand-alone or as a client in a client/server configuration. Microsoft Dynamics NAV client is not needed to use the Microsoft Dynamics NAV ODBC driver.

The main purpose for using ODBC with Microsoft Dynamics NAV is integration with other applications. By using ODBC, users can use applications such as a word processor to create mail merge documents or a spreadsheet application to pull account information and create graphs based on that information.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 19: Na2009 enus devi_13

Chapter 13: Integration Options

13-19

Architecture

The Microsoft Dynamics NAV ODBC has four components:

• Application - Performs processing and calls ODBC functions to submit Microsoft SQL statements and retrieve results.

• Driver Manager - Loads and unloads drivers on behalf of an application. Processes ODBC function calls or passes them to a driver.

• Driver - Processes ODBC function calls, submits SQL requests to a specific data source, and returns results to the application. If necessary, the driver modifies an application's request so that the request conforms to syntax that is supported by the associated DBMS.

• Data source - Consists of the data that the user wants to access and its associated operating system, DBMS, and network platform (if any) that is used to access the DBMS.

The following illustration shows the relationship between these four components.

FIGURE 13.11 MICROSOFT DYNAMICS NAV ODBC ARCHITECTURE

There can be multiple drivers and data sources which allow the application to simultaneously access data from more than one data source. The ODBC API is used in two places:

• Between the application and the Driver Manager. • Between the Driver Manager and each driver.

The interface between the Driver Manager and the drivers is sometimes referred to as the service provider interface, or SPI. For ODBC, the application-programming interface (API) and the service provider interface (SPI) are the same; that is, the Driver Manager and each driver have the same interface to the same functions.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 20: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-20

Requirements

There are several requirements to use the Microsoft Dynamics NAV ODBC driver, they are as follows:

• License for Microsoft Dynamics NAV ODBC granule. • Users are able to connect to the Microsoft Dynamics NAV database

either through a server connection (by using Microsoft Dynamics NAV database server) or through a local connection (the database is located in the client computer).

• Users have permission to access the database. For example, if a user does not have read permission for specific table related data, they cannot read that table from either Microsoft Dynamics NAV client or from Microsoft Dynamics NAV ODBC. Also, ODBC users must have permission for System 9130, C/ODBC.

• There are enough sessions for the users. Just as accessing the Microsoft Dynamics NAV database by using a client, accessing the database by using ODBC also requires a session.

Furthermore, if a local connection is used, only one connection to the database file can exist at any time. Also, the local license file (fin.flf) that is located in the client folder must contain the Microsoft Dynamics NAV ODBC granule.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 21: Na2009 enus devi_13

Chapter 13: Integration Options

13-21

Installation

By default, the Microsoft Dynamics NAV ODBC driver is not installed when installing Microsoft Dynamics NAV 2009. The following figure shows the option to install the Microsoft Dynamics NAV ODBC.

FIGURE 13.12 INSTALL MICROSOFT DYNAMICS NAV ODBC

Limitations

There are several limitations when working with Microsoft Dynamics NAV ODBC, they are as follows:

• Data that is entered through ODBC is not validated. It is important to ensure the data entered meets the criteria of the data type for that field.

• Entries made by ODBC do not fire triggers, therefore any fields that might get automatically filled in when entering data by using the Microsoft Dynamics NAV client, has to be manually populated.

• The ODBC driver does not support outer joins. • The ODBC driver does not work with SQL server. Use the Microsoft

SQL ODBC driver instead. Flow fields are not calculated, because of the way they are stored on the SQL server.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 22: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-22

• Microsoft® Access® supports zero-length strings. Microsoft Dynamics NAV ODBC does not convert the zero-length string to a value that can be used by the Microsoft Dynamics NAV database. Therefore, the zero-length string is interpreted as a NULL value and the error message is returned.

• The Microsoft Dynamics NAV ODBC driver does not support parameter fields which Microsoft Access uses when external tables are linked.

Demonstration: Use Microsoft Dynamics NAV ODBC The following demonstration shows how to set a data source and use it with Microsoft® Excel® and Microsoft Access to read data from and write data to Microsoft Dynamics NAV.

Set a Data Source

The following steps show how to create a DSN.

1. Go to Control Panel and click the Administrative Tools. 2. Click Data Sources (ODBC).The ODBC Data Source Administrator

window opens. 3. Click the System DSN tab and then click Add.

NOTE: User DSN is available for the current user and System DSN is available for all users on the current machine

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 23: Na2009 enus devi_13

Chapter 13: Integration Options

13-23

4. Select Microsoft Dynamics NAV Driver and then click Finish. The Dynamics NAV ODBC Setup window opens.

5. Enter the necessary information and then click OK to complete creating the DSN.

FIGURE 13.13 THE DYNAMICS NAV ODBC SETUP WINDOW

Read Data from Microsoft Dynamics NAV

The following steps show how to use the DSN created previously to return data from Microsoft Dynamics NAV to Microsoft Excel.

1. Start Microsoft Excel with a new workbook. 2. Open the Data Connection Wizard, select ODBC DSN and then

click Next. 3. Select Dynamics NAV ODBC Sample and then click Next. 4. Select Cust_ Ledger Entry table and then click Next. 5. Click Finish. The Import Data window opens. Here developers

can click Properties to open the Connection Properties window where they can customize the connection such as edit the queries and so on.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 24: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-24

6. Click OK. The records from the Cust. Ledger Entry table are displayed in the Microsoft Excel worksheet.

FIGURE 13.14 THE RESULT IN MICROSOFT EXCEL

Write Data to Microsoft Dynamics NAV

The following steps show how to use the DSN created previously to use Microsoft Access to write data to Microsoft Dynamics NAV.

1. Start Microsoft Access with a new blank database. 2. Create a linked table by using the ODBC Database. The Select

Data Source window opens. 3. Select Dynamics NAV ODBC Sample as the DSN. The Link

Tables window opens. 4. Select Location and then click OK. 5. Double-click the Location table in Microsoft Access. It displays the

record from the Location table from Microsoft Dynamics NAV. 6. Type the following.

Code Name Address

BLACK Black Warehouse

2 Late St

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 25: Na2009 enus devi_13

Chapter 13: Integration Options

13-25

7. Close the table and close Microsoft Access. 8. Verify the record is added from Microsoft Dynamics NAV from the

Location Card form.

FIGURE 13.15 THE LOCATION CARD FORM

C/FRONT C/FRONT is an application programming interface that can be used to access Microsoft Dynamics NAV databases. C/FRONT facilitates high-level interaction with the Microsoft Dynamics NAV database and allows developers to manipulate any Microsoft Dynamics NAV database.

The central component of C/FRONT is a library of C functions. These functions give developers access to every aspect of data storage and maintenance, and allow developers to integrate both standard and custom applications with the Microsoft Dynamics NAV database.

Because C/FRONT is a front end to Microsoft Dynamics NAV, developers might want to use C/FRONT to add, delete or view data from their own applications. C/FRONT is much faster compared to the Microsoft Dynamics NAV ODBC driver and is as close to the native connection as with Microsoft Dynamics NAV. However, to use C/FRONT, developers must use some other programming language such as C++, C, or Visual Basic. C/FRONT provides two methods of accessing Microsoft Dynamics NAV which is either through a C style DLL or through the use of the OCX interface.

Requirements

There are several requirements to use C/FRONT, they are as follows:

• License for C/FRONT granule. • C/FRONT is very particular and looks in different places at different

times for the license file. Ensure that the license is loaded everywhere it needs to be, that is the client, server, and so on.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 26: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-26

• Users have permission to access the database. For example, if a user does not have read permission for specific table related data, they cannot read that table from either the Microsoft Dynamics NAV client or by using C/FRONT. Also, users must have permission for System 9110, C/FRONT.

• There are enough sessions for the users. Just as accessing the Microsoft Dynamics NAV database by using a client, accessing the database by using C/FRONT also requires a session.

Installation

By default, C/FRONT is not installed when installing Microsoft Dynamics NAV 2009. The following figure shows the option to install C/FRONT.

FIGURE 13.16 INSTALL C/FRONT

NOTE: When C/FRONT is installed, two .dll files - cfront.dll and cfrontsql.dll are copied. If Microsoft SQL Server is used, select cfrontsql.dll, otherwise select cfront.dll.

Generally, the C/FRONT library (cfront.dll/cfrontsql.dll) reads the registry to locate the Microsoft Dynamics NAV client. However, if multiple Microsoft Dynamics NAV are installed or if Microsoft Dynamics NAV is not present on the system, the function SetNavisionPath in the cfront.dll/cfrontsql.dll library must be called to specify the path to the directory where Microsoft Dynamics

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 27: Na2009 enus devi_13

Chapter 13: Integration Options

13-27

NAV is installed or to a directory containing the following files from Microsoft Dynamics NAV.

• dbm.dll • nc_netb.dll • nc_tcp.dll • slave.exe • fin.etx • fin.stx • fin.flf

List of C/FRONT Files

C/FRONT consists of the following files.

File name Description

cfront.dll C/FRONT C-API library for Microsoft Dynamics NAV Database Server

cfrontsql.dll C/FRONT C-API library for Microsoft SQL Server

cfront.ocx C/FRONT OCX

cf.h C/FRONT header file

libload.c Source file containing functions to load and unload cfront.dll

dberror.txt Database error/return codes

A sample application (written in C) and a .NET application are installed together with C/FRONT installation.

Limitations

There are several limitations when working with C/FRONT, they are as follows:

• Entries made by C/FRONT do not fire triggers to execute any code validation.

• Only active keys are available to C/FRONT. Keys cannot be activated within C/FRONT.

• Microsoft Windows does not go in to standby or hibernation if there is an open server connection from C/FRONT.

OCX Custom controls are also known as OLE Controls and Microsoft ActiveX® Controls. Because they often have the extension .ocx, they are also known as OCXs.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 28: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-28

NOTE: Custom controls can also have the extension .dll.

OCX lets developers take advantage of code that is made commercially available or allows them to write code once and have the ability to call that code from any program that supports custom controls.

The main reason to use custom controls is to save development time and reduce costs.

Requirements

There are several requirements to use OCX, they are as follows:

• License for OCX granule. This is needed only for development. The customers, who run the objects, do not need the OCX granule. They only need the compiled object loaded on their computers along with the custom control that needs to be registered.

• To use a custom control, it must be loaded on the computer that is being used for development and all other computers that use the application that uses the custom control. Therefore, an important part of using an OCX that is developed by another company is to ensure that the developer working on this has the license to redistribute the OCX. The OCX must be installed on each machine that needs to use the code. After the OCX is copied to a machine, register the control from the Microsoft Dynamics NAV Classic client.

• Users must have permission for System 9140, C/OCX to be able to run an object that works with an OCX.

Installation

The first requirement for using a custom control is that it is physically installed on the target machine. But a control also has to be registered with the operating system to be used. If the control is already physically installed by copying it to the hard disk, but is not yet registered, use the following steps to register the control from the Microsoft Dynamics NAV Classic client.

1. Copy the control from the distribution media to the hard disk. 2. On the Microsoft Dynamics NAV Classic client, click Tools,

Custom Controls. The Custom Controls window opens. 3. Click Control, Browse. The Register Custom Control window

opens. 4. Locate the OCX, select it, and click Open. This registers the control

with the system. A confirmation message appears after the registration is complete.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 29: Na2009 enus devi_13

Chapter 13: Integration Options

13-29

5. Click OK to return to the Custom Controls window. Verify that the control is added by closing this window and click Tools, Custom Controls again.

FIGURE 13.17 THE CUSTOM CONTROLS WINDOW

Limitations

There are several limitations when working with OCX, they are as follows:

• When an object is modified and that object depends on an OCX that is not registered on the development computer, the object cannot be compiled.

• Incoming data must conform to C/AL data type. For example, strings are limited to 1024 characters in Microsoft Dynamics NAV. Therefore, custom controls being used must return the appropriate string value.

• Only non-visual controls are supported. This means graphical elements cannot be added to a C/SIDE object (for example, a third party control cannot be added to a form). However, developers can use controls that display information and interact with the user in a window of its own.

• C/SIDE does not allow the retrieval of information about exceptions from a control or automation server through the Invoke method of the IDispatch interface and the EXCEPINFO structure. There are ways to work around this limitation.

• C/SIDE does not support call back for OCX. Therefore, developers cannot respond to an event from OCX.

Demonstration: Use OCX Controls To demonstrate the ease of registering and using a custom control in Microsoft Dynamics NAV, the C/FRONT.OCX is used.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 30: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-30

This demonstration uses this control to create a form that connects to a server, opens a database, and then opens a company and returns the number of records in a table. This page has access to the functions and properties supported by the C/FRONT OCX.

Define Variables for the New Form

The following steps show how to create a new page and define the necessary variables.

1. Create a new blank form. 2. Click View, C/AL Globals. The C/AL Globals window opens. 3. Define the following variables in the Variables tab.

Name DataType Subtype Length cfront OCX CFRONT

Control

TableNo Integer

MyCompany Text 50

MyDatabase Text 50

MyServerName Text 50

Driver Option

4. Open the Properties window for the Driver variable and set the

OptionString property to NDBCS,NDBCN.

FIGURE 13.18 THE C/AL GLOBALS WINDOW

5. Close the Properties window and compile and save the form with

the ID 90005 and the Name Test OCX Form.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 31: Na2009 enus devi_13

Chapter 13: Integration Options

13-31

Design the Form

The following steps show how to add controls to the form.

1. Open the Toolbox and add five text boxes with attached labels to the form.

2. Set the Caption and SourceExpr property of the text boxes as follows:

Text Box Caption SourceExpr

1 Server MyServerName

2 Database MyDatabase

3 Company MyCompany

4 Server Type Driver

5 Table No. TableNo

3. Add a command button to the form. 4. Set the Caption property of the command button to Connect.

FIGURE 13.19 THE FORM DESIGNER

Add Code to the Form

The following steps show how to add code to the form.

1. Select the command button, and then click View, C/AL Code. The C/AL Editor opens.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 32: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-32

2. Type the following code in the OnPush trigger of the button.

CLEAR(cfront); cfront.ConnectServerAndOpenDatabase(FORMAT(Driver),MyServerName,'tcp',MyDatabase,0,FALSE,TRUE,'','');

cfront.OpenCompany(MyCompany); IF cfront.OpenTable(TableNo,TableNo) THEN MESSAGE('The %2 table contains %1 records',cfront.RecCount(TableNo),cfront.TableName(TableNo)); cfront.CloseTable(TableNo); MESSAGE('Table closed'); cfront.CloseCompany(); MESSAGE('Company Closed'); cfront.DisconnectServer(); MESSAGE('Disconnect')

3. Close the C/AL Editor, and then compile, save and close the form.

Run the Form

Run the form in the Classic client, enter valid information and then click the Connect button.

FIGURE 13.20 THE TEST OCX FORM

Automation Server Automation provides a seamless interface to applications outside Microsoft Dynamics NAV 2009 without user intervention. For example, a letter can be created in Microsoft® Word whenever certain conditions take place, such as when a new customer is added.

The main purpose of using Automation is to provide a seamless interface to outside applications without user intervention. A second reason for using automation is to save development time which also reduces the cost of development.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 33: Na2009 enus devi_13

Chapter 13: Integration Options

13-33

Requirements

There are several requirements to use Automation, they are as follows:

• The program to be used as Automation must be an Automation server. Examples of automation servers include Microsoft Word, Microsoft Excel, and Microsoft® Outlook®.

• The Automation server must be loaded on the computer that is being used for development and all other computers that use the application that use the Automation.

Installation

The following steps outline the procedures for using an Automation server from C/SIDE.

1. Declare the top-level interface (class) of the Automation server as a variable of type Automation.

2. Declare all the other interfaces (classes) as variables of type Automation.

3. Use the C/AL function CREATE on the variable declared in step 1. Do not use CREATE on any other variables.

4. Use the methods and properties of the Automation server in the C/AL code. Write the code in this step. The syntax and the semantics of these methods and properties are described in the documentation for each Automation server. Using these methods and properties in C/AL does not involve any new or modified syntax.

5. Use the C/AL function CLEAR to destroy the top-level object. Otherwise, it is destroyed automatically when the variable goes out of scope.

Considerations

There are two major concerns when deciding where to write code that uses Automation.

• The first is the fact that an object that uses Automation can be compiled only if the Automation server is installed on the machine where the compilation takes place. This means that if an object is to be recompiled and modified on a machine where the Automation server is not installed, developers have to modify the code drastically to compile it again. Therefore, it is recommended to isolate code that uses Automation in separate codeunits.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 34: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-34

• The second concern is performance. There is some overhead involved in using an Automation server by using the CREATE function call. If the Automation server is to be used repetitively, it gives better performance if the code is arranged so that the Automation server is created only one time, as opposed to using a series of CREATE/CLEAR function calls.

Because these two concerns sometimes clash, there may be instances when developers must make some trade-offs based on the actual context in which their code is used.

Creating the Variables

To control a Automation server, developers define a variable (global or local) of type Automation and reference the Automation Server as the subtype of this variable. The only Automation Servers that appear in the list are those that are loaded on the development machine.

Once the Automation Server is selected, a list of all the classes available for that Automation server is displayed. Typically, the application is the first class selected. Afterwards, declare variables for all the other interfaces (classes) that control or interact with the code.

Determining what classes must be defined depends on the understanding of the Automation server. If these are Microsoft programs, to determine what each of the classes do, view the Microsoft Visual Basic Help. Generally, which classes to use is determined by considering the application. For example, to call Microsoft Word, consider the application and then the document. Likewise, if to call Microsoft Excel, consider the application, the workbook, the worksheet, and the Range of cells.

Responding to Events

C/SIDE can receive events from the Automation servers that it controls. When declaring a global variable of the type Automation, set the WithEvents property for the variable to specify whether to receive events. Setting the WithEvents property to Yes automatically generates C/AL triggers for the events that the component provides.

A trigger name consists of the name of the Automation variable followed by "::<Event name>." For example, if an Automation variable named MyEventVar, and the component provides the event MessageReceived(...), the name of the trigger is MyEventVar::MessageReceived(...).

NOTE: If a global variable of type Automation is deleted, the event triggers and their code are also deleted. Furthermore, if the DataType or SubType for a global variable is modified, then all the event triggers and their code are deleted.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 35: Na2009 enus devi_13

Chapter 13: Integration Options

13-35

Limitations

There are several limitations when working with Automation, they are as follows:

• When an object is modified and that object depends on an Automation that is not registered on the development computer, the object cannot be compiled.

• C/SIDE does not allow the retrieval of information about exceptions from a control or automation server through the Invoke method of the IDispatch interface and the EXCEPINFO structure. There are ways to work around this limitation.

• Incoming data must conform to C/AL data type. For example, strings are limited to 1024 characters in Microsoft Dynamics NAV.

In addition, when C/SIDE is enabled to receive events from the Automation server, that is, the WithEvents property is set to Yes, there are limitations to the triggers that are automatically generated which are provided by the Automation.

Demonstration: Create a Report with Automation The following demonstration shows how to create a report with Automation capabilities.

Define Variables for the New Report

The following steps show how to create a new report and define the necessary variables.

1. Create a new blank report. 2. Add Customer for the data item. 3. Click View, C/AL Globals. The C/AL Globals window opens. 4. Define the following variables in the Variables tab.

Name DataType Subtype Length

CustAmount Record Customer Amount

CustFilter Text 250

CustDateFilter Text 30

j Text 30

NoOfRecordsToPrint Integer

i Integer

MaxAmount Decimal

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 36: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-36

5. Open the Properties window for the CustAmount variable, set the Temporary property to Yes and then close the Properties window.

6. Define several other variables.

Name DataType Automation Server Automation Object

Excel Automation Microsoft Excel 12.0 Object Library

Application

Book Automation Microsoft Excel 12.0 Object Library

Workbook

Range Automation Microsoft Excel 12.0 Object Library

Range

Sheet Automation Microsoft Excel 12.0 Object Library

Worksheet

Chart Automation Microsoft Excel 12.0 Object Library

Chart

NOTE: The Microsoft Excel version may vary.

FIGURE 13.21 THE C/AL GLOBALS WINDOW

7. Compile and save the report with the ID 90002 and the Name

Sample Automation.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 37: Na2009 enus devi_13

Chapter 13: Integration Options

13-37

Change the Report Properties and Add Code to the Report

The following steps show how to change the report properties and add code to the report.

1. Open the Properties window for the report, and set the ProcessingOnly property to Yes, and then close the Properties window.

2. Click an empty line in the Report Designer and then click View, C/AL Code. The C/AL Editor opens.

3. Add the following code in the OnPreReport trigger.

CustFilter := Customer.GETFILTERS; CustDateFilter := Customer.GETFILTER("Date Filter");

4. Close the C/AL Editor. 5. Click the Customer data item, and then click View, C/AL Code.

The C/AL Editor opens. 6. Add the following code in the OnPreDataItem trigger.

i := 0; NoOfRecordsToPrint := 10; CustAmount.DELETEALL; CurrReport.CREATETOTALS("Sales (LCY)","Profit (LCY)");

CREATE(Excel); Excel.Visible(TRUE);

Book:=Excel.Workbooks.Add(-4167); Sheet:=Excel.ActiveSheet; Sheet.Name := 'TOP 10';

The first four lines of the code initialize values to variables, delete records in the Customer Amount table and maintain totals for two fields when iterating the Customer data item.

The fifth line creates an instance of Microsoft Excel and the sixth line makes the Microsoft Excel visible.

NOTE: Microsoft Excel generates a General Protection Fault error when closing an Excel worksheet that is created when Microsoft Excel is invisible. To solve the problem, make Microsoft Excel visible immediately after a new worksheet is created. Alternatively, make Microsoft Excel visible just before creating a new Excel worksheet, and then make it invisible immediately after the worksheet is created.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 38: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-38

The seventh to the tenth lines add a workbook to the application, use the ActiveSheet property of the application to ensure that what is done next affects the active sheet of the new workbook and then give a name to the sheet.

7. Add the following code in the OnAfterGetRecord trigger.

CALCFIELDS("Sales (LCY)","Profit (LCY)"); IF ("Sales (LCY)" = 0) AND ("Profit (LCY)" = 0) THEN CurrReport.SKIP;

CustAmount.INIT; CustAmount."Customer No." :="No."; CustAmount."Amount (LCY)" := -"Sales (LCY)"; CustAmount."Amount 2 (LCY)" := -"Profit (LCY)"; CustAmount.INSERT; IF (NoOfRecordsToPrint = 0) OR (i < NoOfRecordsToPrint) THEN i := i + 1 ELSE BEGIN CustAmount.FINDLAST; CustAmount.DELETE; END;

The first line of the code calls the CALCFIELDS function to calculate the values for Sales (LCY) and Profit (LCY). The second line of the code checks whether both the fields equal zero. If they do, the record is skipped. Otherwise, it proceeds to the next lines of code.

The third to seventh lines of code initialize the CustAmount record, assign the Customer No. and the amounts field, and insert the record. The negative value is used so that the graph displays upright.

If the NoOfRecordsToPrint equals zero or the value i is less than the NoOfRecordsToPrint, increment i. Otherwise, find the last record and delete it. The reason for doing this is that as a record is inserted, the records are placed in order from highest to lowest (based on the key in the Customer Amount table). Therefore, the CustAmount table will have only the top 10 records for the amount.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 39: Na2009 enus devi_13

Chapter 13: Integration Options

13-39

8. Add the following code in the OnPostDataItem trigger.

Sheet.Range('A2').Value := 'No.'; Sheet.Range('B2').Value := 'Name'; Sheet.Range('C2').Value := 'Sales (LCY)'; Sheet.Range('D2').Value := 'Profit (LCY)';

IF CustAmount.FINDSET THEN BEGIN j:='3'; REPEAT Customer.GET(CustAmount."Customer No."); Sheet.Range('A'+j).Value := CustAmount."Customer No."; Sheet.Range('B'+j).Value := Customer.Name; Sheet.Range('C'+j).Value := -CustAmount."Amount (LCY)"; Sheet.Range('D'+j).Value := -CustAmount."Amount 2 (LCY)"; j:=INCSTR(j); UNTIL CustAmount.NEXT = 0; END;

Range:=Sheet.Range('B3:D12'); Chart:=Book.Charts.Add; Chart.Name := 'Top 10 Customers - Graph'; Chart.ChartWizard(Range,-4100,2,2,1,0,0,'Top 10 Customers','Customer','Sales (LCY)');

These lines of code write data from the CustAmount table to the Microsoft Excel instance. The last five lines of code add a chart to the Microsoft Excel instance by first setting a range based on the rows and column in the Excel sheet and then using the ChartWizard to plot the chart.

9. Compile, save and close the report.

Run the Report

Run the report in the Classic client and click OK at the Request Form.

FIGURE 13.22 THE RESULT IN THE MICROSOFT EXCEL WORKSHEET

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 40: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-40

The following chart is displayed in Microsoft Excel.

FIGURE 13.23 THE CHART IN THE MICROSOFT EXCEL WORKSHEET

Summary Microsoft Dynamics NAV 2009 offers a set of technologies to integrate with external applications, they include the following:

• Web service • Microsoft Dynamics NAV ODBC • C/FRONT • OCX • Automation

Each of the technology has its own advantage and disadvantage over one another and the choice of which technology to use can depend on many factors. Understanding integration options available to Microsoft Dynamics NAV 2009, completes the introduction to C/SIDE development.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 41: Na2009 enus devi_13

Chapter 13: Integration Options

13-41

Test Your Knowledge 1. What must be done to use Microsoft Dynamics NAV ODBC? (Select the

correct answers.)

o Install Microsoft's ODBC driver. o Purchase the Microsoft Dynamics NAV ODBC granule. o Set up permissions for the users. o Set up a DSN.

2. True or False. Any Microsoft Dynamics NAV ODBC version can be used to open up any Microsoft Dynamics NAV database.

3. True or False. Microsoft Dynamics NAV uses Microsoft's ADO for all connections.

4. True or False. Microsoft Dynamics NAV ODBC driver supports outer joins.

5. True or False. Entering data through ODBC is validated just as in the Microsoft Dynamics NAV client.

6. What is C/FRONT?

7. Does C/FRONT use a session?

8. Can keys be activated from within C/FRONT?

9. True or False. C/FRONT does not require any files from the Microsoft Dynamics NAV client directory.

10. What is the purpose of using OCX control?

11. What must be done to use OCX control?

12. What may be the reason for not being able to select OCX as a data type?

13. Is calling a method or setting properties of an OCX any different from any other standard Microsoft Dynamics NAV object?

14. What is the purpose of using Automation in Microsoft Dynamics NAV?

15. Yes or No. It is possible to respond to Automation Events in Microsoft Dynamics NAV?

16. True or False. The CREATE function must be used before using an Automation object.

17. True or False. The FREE function is used to release the Automation object from memory.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement

Page 42: Na2009 enus devi_13

C/SIDE Introduction in Microsoft Dynamics® NAV 2009

13-42

Quick Interaction: Lessons Learned Take a moment and write down three key points you have learned from this chapter

1.

2.

3.

Microsoft Official Training Materials for Microsoft Dynamics ® Your use of this content is subject to your current services agreement