How “Business Central OData V4 Unbound Actions” and “Xamarin” are a perfect match.

THE MOBILE PERSPECTIVE IN QUERY ODATA AND API

I initially found it difficult to implement complex interfaces between Business Central and Xamarin mobile apps by using ODATAv4 and API Pages.

Luckily Busines Central offers plenty of solutions to implement interfaces and both OData Bound and Unbound Actions are really awesome features.

One of common scenario I have to deal with is a mobile app showing sales prices, discounts and availability for a specific item for a customer.

In this situation, I prefer to leave to Business Central the logic to determine the right price and discount for the item because often this evaluation involves a custom logic implemented on BC side and the final price is not obtained as it would be with the standard.

Moreover with BC v16 a new logic and interface for price evaluation has been introduced and the “Sales Price” is now obsolete:

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-extending-best-price-calculations

STEP 1: THE BUSINESS CENTRAL DATA UNBOUND ACTION

This is the sample codeunit with two different type of parameters.

In the first procedure I pass a generic JSON and then I deserialise it.

In the second procedure I pass direct parameters.

STEP 2: MAP THE CODEUNIT IN WEB SERVICES

The configuration may be managed via WSPublishing.xml.

STEP 3: TEST THE API WITH INSOMNIA

The POST for the two procedures:

The company is passed as an header parameters. May be passed in the URL too but I on my opinion the header solution is easier for Xamarin Forms implementation.

STEP 4: THE XAMARIN HTTP REQUEST

The Json input class:

This is the Business central JSON mapped in the C# class:

The Xamarin Forms Request with the company passed as http header.

REFERENCES

Creating and Interacting with an OData V4 Unbound Action

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-creating-and-interacting-with-odatav4-unbound-action

Stefano Demiliani Dynamics 365 Business Central: using OData V4 Bound Actions

https://demiliani.com/2019/06/12/dynamics-365-business-central-using-odata-v4-bound-actions/

Codeunit API’s in Business Central

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-view-table-data

LAST UPDATED

18th of April, 2021

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s