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

BC Open Source? How to start?

BC Open Source? How to start?

BC Open Source? How to start? One of the most exciting news introduced last month in Lyon during Directions EMEA 2023 was the changes to the open-source initiative. This means that you can now contribute to the source code of the Base app and the System app, which are...

read more
Validate a FlowField Field. Wait? What?

Validate a FlowField Field. Wait? What?

Validate a FlowField Field. Wait? What? There are not many things in the AL Language that surprised me. However, last week, I found one such thing - I reviewed customizations made by another partner and had to analyze the OOTB code of the Demand Forecast matrix. I run...

read more
Dynamics NAV 2013 & Expired Cronus License

Dynamics NAV 2013 & Expired Cronus License

We found an interesting problem - we were not able to run the development environment for Dynamics NAV 2013. Whenever we tried to run the development client, we got the following error message: "Your program license has expired" and the development client has closed...

read more
Indirect Dependencies and Access Modifiers

Indirect Dependencies and Access Modifiers

Last week, there was a discussion on Yammer on how to get values from the "Sent Email" record when all fields are marked as Internal. I was surprised that many people do not know what can/can't access modifiers (such as local, protected, or internal) be used for. I...

read more
AL Extensions: Replace Document Attachment

AL Extensions: Replace Document Attachment

I have published a new simple, open-source extension that allows replacing existing document attachments in all master entities as well as in open documents. The source code as well as the app file that can be installed in your environment is available on my GitHub...

read more

Sign Up for News

Certifications

Highest certification
Microsoft Data Management and
also in D365 Business Central

Microsoft Certified: Dynamics 365 Business Central Functional Consultant Associate

See other certifications here