Reader small image

You're reading from  Dynamics 365 Business Central Development Quick Start Guide

Product typeBook
Published inAug 2018
PublisherPackt
ISBN-139781789347463
Edition1st Edition
Concepts
Right arrow
Authors (2):
Stefano Demiliani
Stefano Demiliani
author image
Stefano Demiliani

Stefano Demiliani is a Microsoft MVP on Business Applications and Azure, MCT, Microsoft Certified Solution Developer (MCSD), Azure Certified Architect, and an expert in other Microsoft related technologies. His main activity is architecting and developing enterprise solutions based on the entire stack of Microsoft technologies (mainly focused on ERP and serverless applications). He has worked with Packt Publishing on many IT books related to Azure cloud applications and Dynamics 365 Business Central and is a frequent speaker at IT conferences around Europe. In his free time Stefano is also a runner and a cyclist.
Read more about Stefano Demiliani

Duilio Tacconi
Duilio Tacconi
author image
Duilio Tacconi

Duilio Tacconi is a Microsoft Dynamics NAV/Microsoft Dynamics 365 Business Central Escalation Engineer at Microsoft EMEA Customer Support & Services (CSS). He joined Microsoft in 2008 after working in a customer IT department with a focus on system administration and development. Despite graduating with the highest score in Agricultural Science in 1996, he is in the ERP circuit since 1998 as developer and system implementer for several companies with Microsoft and non-Microsoft technologies. Currently, he is a subject matter expert in EMEA for RDLC Report development and one of Microsoft EMEA CSS reference for Managed Service for Partners (MSfP). Three times IronMan finisher, Duilio lives in Cernusco Sul Naviglio (Italy) with his beloved wife Laura and his 2 years old son Leonardo.
Read more about Duilio Tacconi

View More author details
Right arrow

Chapter 7. Integration and Serverless Processing

InChapter 6Deploying Extensions, we saw how to deploy an extension to Dynamics 365 Business Central (sandbox or production environments) and how to debug our deployed code.

In this chapter, we'll see how we can integrate Dynamics 365 Business Central with external applications and how we can use some Azure-powered services in order to create serverless business processes. Here, you will learn the following:

  • How to integrate with Dynamics 365 Business Central by using APIs and web services
  • How to use Azure Functions and .NET code with Dynamics 365 Business Central
  • How to interact with Microsoft Flow and Microsoft PowerApps to build serverless workflows

Dynamics 365 Business Central web services


When talking about integrating Dynamics 365 Business Central with external applications in a service-oriented way, we have essentially two main roads: use SOAP and OData web services, or use REST APIs.

To publish a NAV entity as a SOAP web service, you have to go to the web service page in Dynamics 365 Business Central. For this sample, we want to create a web service to access the Item entity, so we create a new record by inserting the following values:

  • OBJECT TYPE: Page
  • OBJECT ID: 30
  • SERVICE NAME: Item
  • PUBLISHED: true

Dynamics 365 Business Central automatically gives you the URLs for the OData and SOAP endpoints:

Now, you can access your published web service from an external application able to use SOAP web services.

To create a web service client, open Visual Studio and create a new Console application project (here called D365BCWebServiceClient). Now, right-click on your project and select Add a Service Reference.

In the Address box, enter the SOAP...

Dynamics 365 Business Central REST APIs


At the time of writing, Dynamics 365 Business Central offers 44 standard APIs available for integration with external applications.

REST APIs permit you to create any type of application in any code language that interacts with Dynamics 365 Business Central by using HTTP CRUD operations (create, retrieve, update, delete).

To start using the APIs, you need to authenticate through Dynamics 365 Business Central. There are essentially two ways to authenticate:

  • Basic authentication: Log in to Dynamics 365 Business Central, select the Users page, select the user you want to use, click on the Web Service Access Key field, and generate a key. The generated key will be the password that you have to use for authentication, together with your username. The API endpoint to use is the following: https://api.businesscentral.dynamics.com/v1.0/<yourtenantID>/api/beta.
  • Azure Active Directory (AAD) authentication: This is what should be used in a production environment...

DotNet variables


In the on-premise Microsoft Dynamics NAV world, many integrations with external applications are performed by using DotNet add-ins. The use of DotNet variables in Microsoft Dynamics 365 Business Central in the cloud (SaaS version) is actually not supported.

You can use DotNet variables only if your extension targets the on-premises version of Microsoft Dynamics 365 Business Central. For this, you have to set "target": "Internal" in your app.json file in Visual Studio Code:

A .NET type in the AL language is declared in the following way:

dotnet
{
    assembly(ASSEMBLY_NAME)
    {
        type(DOTNET_TYPE; ALIAS){}
    }
}

In preceding code, we can see the following:

  • ASSEMBLY_NAME is the name of the assembly to reference
  • DOTNET_TYPE is the .NET type to reference in the selected assembly (fully qualified name)
  • ALIAS is an alias used to reference the .NET type from the AL code

When using DotNet from AL, you need to provide to Visual Studio Code, and to the AL compiler, the paths on...

Azure Functions


Azure Functions is a serverless compute service offered by the Azure platform for running on-demand and event-driven code in the cloud. Azure Functions are actually the only way to run .NET code in the Dynamics 365 Business Central cloud platform (SaaS).

You can use an Azure Functions to migrate your existing on-premises .NET code to the cloud. An Azure Functions can be written directly via the Azure Portal (Create a Resource | Function App) or by using Visual Studio (with the Azure development tools installed). This second way is the recommended way if you want to have intellisense and automatic deployment.

To start creating an Azure Functions with Visual Studio, start a new project and select CloudAzure Functions, give a name to your project, and click OK.

You can now select Azure Functions v1(.NET Framework) or Azure Functions v2 Preview (.NET Standard). Here, we select the v1 version (v2 is for .NET Core and it's currently in preview).

Now Visual Studio asks you to choose...

Microsoft Flow


Microsoft Flow is a cloud-based workflow service that permits you to create automated processes across multiple applications without writing any lines of code.

To start using Microsoft Flow with Dynamics 365 Business Central, log in to https://flow.microsoft.com/ and search for Business Central. Here are the available flows:

To create a new workflow, select one of the available templates (here I've selected the Request approval for Dynamics 365 Business Central Sales Order template).

When selected, a wizard starts. It first shows the connected accounts (Dynamics 365 Business Central Office 365), and in the next window, you can graphically compose your flow by inserting the workflow parameters:

Then you can insert the conditions:

If the order is approved, an email is sent to the order creator:

If the order is not approved, a different notification email is sent to the order approval:

Obviously, you can customize this flow as you want to satisfy your business needs, but this is outside...

Microsoft PowerApps


Microsoft PowerApps is a cloud-based and no-code solution offered by the Office 365 platform to create web- and mobile-data-connected applications.

To create a PowerApps connected to Dynamics 365 Business Central, log in to https://powerapps.microsoft.com/, select the Apps menu on the left, and then click on Create an App:

In the Connection menu, select Microsoft Dynamics 365 Business Central and then click Create. A wizard will create a connection to your Dynamics 365 Business Central tenant.

Now you can choose a dataset to work with (selected from the list of your companies), select a table (from all the tables published as OData web services in Dynamics 365 Business Central), and click Connect:

PowerApps creates a connection to your data, and after few seconds PowerApps Studio is started. Here is the place where you can start building your app:

The PowerApps Studio

You can customize the layout, add more fields to the app pages, and many other things:

If we just start this...

Summary


In this chapter, we saw how we can integrate Dynamics 365 Business Central with external applications by using APIs and web services. We learned how to use Azure Functions (for SaaS) and DotNet assemblies (for on-premise) to extend Dynamics 365 Business Central. Then, we looked at how to create serverless processes and applications with Dynamics 365 Business Central using Azure Function, Flow, and PowerApps.

By the end of this book, you'll be ready to master Dynamics 365 Business Central Development.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Dynamics 365 Business Central Development Quick Start Guide
Published in: Aug 2018Publisher: PacktISBN-13: 9781789347463
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Stefano Demiliani

Stefano Demiliani is a Microsoft MVP on Business Applications and Azure, MCT, Microsoft Certified Solution Developer (MCSD), Azure Certified Architect, and an expert in other Microsoft related technologies. His main activity is architecting and developing enterprise solutions based on the entire stack of Microsoft technologies (mainly focused on ERP and serverless applications). He has worked with Packt Publishing on many IT books related to Azure cloud applications and Dynamics 365 Business Central and is a frequent speaker at IT conferences around Europe. In his free time Stefano is also a runner and a cyclist.
Read more about Stefano Demiliani

author image
Duilio Tacconi

Duilio Tacconi is a Microsoft Dynamics NAV/Microsoft Dynamics 365 Business Central Escalation Engineer at Microsoft EMEA Customer Support & Services (CSS). He joined Microsoft in 2008 after working in a customer IT department with a focus on system administration and development. Despite graduating with the highest score in Agricultural Science in 1996, he is in the ERP circuit since 1998 as developer and system implementer for several companies with Microsoft and non-Microsoft technologies. Currently, he is a subject matter expert in EMEA for RDLC Report development and one of Microsoft EMEA CSS reference for Managed Service for Partners (MSfP). Three times IronMan finisher, Duilio lives in Cernusco Sul Naviglio (Italy) with his beloved wife Laura and his 2 years old son Leonardo.
Read more about Duilio Tacconi