Skip to main content

Creating APIs in Business Central - 1

Introduction:
While writing a blog on Automated Testing in Business Central, I was going through sample apps provided by Microsoft and realized that the complexity is nowhere close to what examples Microsoft has provided on docs.microsoft.com. In this blog, I will try to explain how APIs work and how to be creative with the implementation. Also, an API which were in beta are finally out with version V1.0 in the April 2019 release let's see some important key things from development aspects.
This blog is going to be theoretical one kindly bear with me.


Pre-requisites:

Books & References:
  • API V1 from Business Central On-Premise DVD
  • API(V1.0) for Business Central (Click Here)
  • API(Beta) for Business Central (Click Here)

Solution:

Key Requirements:
API source table must have an Id(GUID) field per record for masters

API(Page) Properties:
  • APIGroup: Sets the group of an API endpoint that page is exposed in.
  • APIPublisher: Sets the publisher of an API endpoint that page is exposed in.
  • APIVersion: Sets the versions of an API endpoint that page is exposed in.
  • Caption: Caption for the API endpoint.
  • DelayedInsert: Sets a value that specifies whether a user must leave a record before it is inserted into the database
  • EntityName: Sets the singular name of an API endpoint that page is exposed in.
  • EntitySetName: Sets the plural name of an API endpoint that page is exposed in.
  • ODataKeyFields: Specifies the field to select when using OData.
  • PageType: Sets the type of Page to API. All APIs have this property as mandatory.
  • SourceTable: Defines the source table to get data from and to write the data to.
  • DeleteAllowed: Set to declare whether the page can delete the data from the source table.
  • InsertAllowed: Set to declare whether the page can insert a record into the source table.
  • ModifyAllowed: Set to declare whether the page can modify the record from the source table.
  • SourceTableView: Used to sort & filter the data.
  • SourceTableTemporary: Set whether the SourceTable is Temporary or no.
  • RefreshOnActive: Set this property on the page where you want to refresh the recent data on the page after the user navigates from another page.
  • ChangeTrackingAllowed: Sets whether the entity exposed through the OData API supports change tracking.
  • Editable: Sets whether the page allows READ/WRITE or READ ONLY.
API(Query) Properties:
  • APIGroup: Sets the group of an API endpoint that page is exposed in.
  • APIPublisher: Sets the publisher of an API endpoint that page is exposed in.
  • APIVersion: Sets the versions of an API endpoint that page is exposed in.
  • Caption: Caption for the API endpoint.
  • QueryType: Sets the type of Query to create.

Page Field Properties:
  • ApplicationArea: Sets the Application Area that applies to the control.
  • Caption: Caption for the field on the API endpoint.
  • Tooltip: Sets if the tooltips are provided for the control. Tooltips are set based on whatever is assigned.
  • Editable: Sets if the field allows READ/ WRITE or READONLY.
  • NotBlank: Sets a value to specify whether Users must enter a value.
  • Width: Sets the width of the control. Width is set as a number of characters and must be a fixed number when specified.
  • ODataEDMType: Specifies the Entity Data Model Type to be used for this node in the OData metadata. (Refer here: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/entity-data-model)
  • BlankZero: Indicates whether the system displays zeros (0) and No.
  • AutoFormatType: Sets a value that determines how data is formatted, together with the AL expression in the AutoFormatExpression Property.
  • ShowCaption: Sets whether the text that is specified by the Caption Property is displayed for the control.
Page Part Properties:
  • ApplicationArea: Sets the Application Area that applies to the control.
  • Caption: Caption for the field on the API endpoint.
  • EntityName: Sets the singular name of an API endpoint that page is exposed in.
  • EntitySetName: Sets the plural name of an API endpoint that page is exposed in.
  • SubPageLink: Sets the link between the parent page and the Card Page.

Query DataItems Properties: 
  • Caption: Caption for the field on the API endpoint.
  • DataItemLink: Sets a reference between one or more fields of the data item table and parent data item or data items.
  • SqlJoinType: Sets the data item link type between data items in a query to determine the records that are included in the resulting data set.
  • DataItemTableFilter: Sets filters on fields of the underlying table of a query.
Query Feilds Properties:
  • Caption: Caption for the field on the API endpoint.
  • Method: Gets or Sets method as defined in the HTTP standard(Aggregate Function)

When to use the Page and when to use Query in API: 

  • A query is used when data from the multiple tables is to be fetched and aggregated. For Eg: Total Sales for All the Customers.
  • A page is used when the data to be fetched from a single table. For Eg: Customer Master


Note: All the properties used are similar to pages & queries. Choose as suitable.

Conclusion:
In this blog, I've discussed the properties of API (Pages & Queries) which will help us in the creation of API and are crucial for understanding and development of custom APIs as well.
In my next blog(Click Here!), I'll show an implementation side in detail.

Hope this helps! :)

Comments

Popular posts from this blog

How Business Central Modern Client Reverse Compatibility With NAV Can Help You Improve Your Work.

Introduction: Today, I was playing around with Business Central Modern Client (Windows App).
Out of curiosity I was trying to login to one of my NAV 2017 through SSO.
Pre-requisites: Microsoft Dynamics NAV with SSO configured
Microsoft Dynamics Business Central
Demonstration: 1. Business Central App - Main Page:

Clicking on locally hosted service and putting in the credentials configured for NAV 2017 SSO, we get.
Still skeptical when Business Central login into NAV.

2. Business Central App - Reverse compatible with NAV 2017:


Well well well...
Look whose here.
NAV disguised as  Dynamics 365 for Financials.

I think we all agree that Business Central Modern Client is a WebApp version of Busines Central Online. Basically just like browser in an App.
The difference is that it can connect to NAV as it is just like a browser.

3. Does Business Central Modern Client follow DynamicsNAV protocol?:
Well, it simply does not.
It would be amazing  if it did, as it would mean that we could deal with runni…

TIP: Working with changing Field DataTypes and Deleting fields in Business Central

Introduction:
Imagine a scenario where as per the requirements provided by your clients, you have set up the Database structure in NAV/Business Central.
Then comes a requirement in Phase 2 which completely redefines the database structure which was provided by you and you need to delete a few fields in a table and move it to another table.

Pre-requisites:
Microsoft Dynamics NAV
Microsoft Dynamics Business Central

Books & References:
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-obsoletestate-property

Solution:
1. In Microsoft Dynamics NAV, there was a flexibility to delete fields, tables, and keys and using  Force-Sync, you can directly delete the field, table, and keys from SQL Database.


2. Whereas in Microsoft Dynamics Business Central, you cannot delete the fields, keys, and tables.
In order to deploy this deleted change, you need to mention this field, table, and keys with Obsolete State Removed.


After you mention the field as…

Enum Object in Business Central - How to create and how to extend!

Introduction:
Since the dawn of Business Central Era (2nd April 2018 - Today), there are many new data types introduced by Microsoft.
One such data type is Enum(Enumeration). Essentially, what enumeration is having a single select value with multiple options at a given time!
Well, I know what your thinking what about the 'Option' data type.
Anyways, enough of talking let's just dive in!

Disclaimer:The knowledge in this blog is true and complete to the best of authors and publishers knowledge. The author and publisher disclaim any liability in connection with the use of this information.
Pre-requisites:
Microsoft Dynamics Business Central (SaaS or On-Premise)
VS code with AL Language extension

Code:
1. Enum as an Object:
Just like Tables and Pages, Enum behaves like an Object.
Note that Extensible means that the Enum Object can be extended in another module. By default, this property is set to TRUE.



Enums and Enum Extensions behave differently. They follow a different number se…