Exploring CosmosDB with Business Central, part 1

by Nov 16, 2021AL Language

Home 9 Development 9 AL Language 9 Exploring CosmosDB with Business Central, part 1

Azure Cosmos DB is a fully managed NoSQL database for modern app development. Data in this database are available using APIs. To find out how to get Azure Cosmos DB, licensing and all other details see Microsoft portal https://docs.microsoft.com/en-us/azure/cosmos-db/introduction.

——————————————————————————————————————

This is the first part of series of three articles about integration between Microsoft Azure Cosmos DB and Microsoft Dynamics 365 Business Central. This part explains how to create Azure Cosmos DB environment (Database, Container), how to add new values to your newly created database and how to obtain your API keys that will be used later for API authorization.

The second part explains how to connect to Cosmos DB using AL Language and how to get values from your database using GET requests. The third and last part describes how to send your own SQL queries using POST request from AL Language to get filtered results based on variable requests made in AL Language.

——————————————————————————————————————

Create database & container

The environment for Azure Cosmos DB can be created directly at Azure portal (https://portal.azure.com/). Once the environment is created, you should be able to create a new database (see image below) using ation “New Database”.

Now you can specify name of your new database. It is important to remember that Database id is always case-sensitive! You do not have to change anything else (other fields can be used for performance & pricing optimalization but are not linked directly to the topic of this series).

In the “standard” database (SQL-based like MSSQL) the database has set of tables that contains fields and store values. In Cosmos DB our database “store” containers. It is not called table as it stores comples objects (JSON) that can vary in the structure and even can store “tables in tables” (complex JSON) object. 

So have already created Database, new we have create at least one Container. 

You can create container in new database or create it in already existing one. As we created database manually in the previous step, choose “Use existing” and select your created database. Specify “Container id” (unique, again it is important to remember the value is case-sensitive).

You have to also specify “Partition key”. This key should be the field that has many different values accross your data and also the field should be used for accesing to the specific record. If you don’t know what to put there, set /id (read the help tooltip for more info). Other fields can be skipped (but you can specify for example unique keys, if you need based on your business requirements).

Now you have both database and container. Go to the “Data explorer” -> “Data” -> Select your database -> Select your container -> Select “Items”.

To define structure (or data, in Cosmos DB these two things are interchangeable) go to “New Item” and put your data in JSON object structure to the text editor. Once you have everyhing defined, save it. See the picture below.

And that’s it! You have created Cosmos DB database with example data. Now you can connect to this database using APIs (we will look at how to do it in the next article). You just need to know your access key which you can find under “Keys” -> “Read-write Keys” or “Read-only Keys” based on your requirements.

Recent Articles from the category

Exploring CosmosDB with Business Central, part 2

Exploring CosmosDB with Business Central, part 2

This part explains how to connect to Azure Cosmos DB from your Business Central extension using AL Language and how to get some values from the database.------------------------------------------------------------------------------------------------------------------...

read more
DynamicsCon 2021 session recording available!

DynamicsCon 2021 session recording available!

Finally, recordings from DynamicsCon 2021 Autumn edition are available! Check the official youtube channel. It was a great conference with over 250 people during my live session! I definitely hope I will be able to attend the next in-person DynamicsCon as a speaker...

read more
Directions EMEA day 0 ;)

Directions EMEA day 0 😉

Directions4Partners EMEA 2021 is still in progress here in Milan. I want to share all details about each day, but unfortunately, there are so many amazing things to see, watch and try I have almost no time. So today just a few words about the day before the...

read more
ErrorInfo data type & Collectible Errors

ErrorInfo data type & Collectible Errors

A major change to AL Language development is here! Collectible errors can hugely improve any validation procedures. And what's new? Everything is about a new data type ErrorInfo. ErrorInfo data type ErrorInfo is a new data type introduced in Microsoft Dynamics 365...

read more
Working with Translation Files (XLIFF)

Working with Translation Files (XLIFF)

How does the translation file work? In Microsoft Dynamic 365 Business Central, displaying different languages is done using the XLIFF files extension (.xlf). The generated XLIFF files have strings that are specified in properties like Captions, Tooltips......

read more
Custom Filter Tokens

Custom Filter Tokens

As a user of the Business Central you have some constants you can use to filter or insert values. These constants contain useful values for data manipulation such as t / today for date field - return current dateq / quarter for date field filters - return range of the...

read more
Field Level Permissions (Restricted Fields)

Field Level Permissions (Restricted Fields)

I just add a new project to my GitHub repositories. It is a new extension for Business Central that extends security functionalities with field-level permission. Using this extension, users are able to define who can or can not change specific fields in any table in...

read more
How to let users choose field(s) properly

How to let users choose field(s) properly

When some complex functionality is developed, it is sometimes necessary to let users choose a specific field. This can be required for field permissions, mapping imported values or any similar process. Earlier, the usual way was to create a link on the Field table...

read more