Bound Actions in Dynamics NAV & Business Central

Bound Actions in Dynamics NAV and Business Central

Since Dynamics NAV 2018, the possibility of using “Bound Actions” was introduced. Surely it’s interesting because before, it was necessary to use workarounds (these workarounds are available in the various forums \ blogs) to simulate the pressure of a key recalling a function, now with this integrated technology, is certainly more convenient and similar to other tools in which they were already available (ex: CRM).

About Bound Actions…

You can publish a Dynamics NAV or Dynamics 365 Business Central function as an OData (Open Data Protocol) V4 web service action”.

 

Before Bound Actions

You could manage the four basic CRUD operations (Create, Read, Update, Delete) data through OData / REST interface.

There was no direct way to call custom code or specific actions like posting a journal.

After Bound Actions introduction…

Now, you can publish a Dynamics NAV or Business Central function as an OData V4 web service action, that means that we can use “Bound Actions” to run specific actions.

These features (Bound Actions) were already available in other tools\applications, but not for Dynamics NAV & BC without using any Workaround. Almost twenty years ago, they were already possible with Microsoft Access…. And now they are also usable in NAV \ BC. Great.

Example:

http://<Server>:<WebServicePort>/ODataV4/Company(‘CRONUS%20International%20Ltd.’)/SalesOrders(<Document Type>,<No.>)/NAV.Post Bound Action

In this case we are calling the “Post function” existing in “Sales Order” page.

Source https://docs.microsoft.com/en-us/dynamics-nav/walkthrough-creating-and-interacting-odata-v4-bound-action

 

“Bound Actions” in Action…

Is also now possible to declare OData “bound actions in AL”; a new attribute and a new AL type have been introduced to achieve this.

OData bound actions in AL

 

Declaring the OData bound action

The following example (in link below) shows you how you can declare an OData bound action on a page exposed as a web service.

For that, you need three simple STEPS

#1 – Add a procedure to the SalesInvoiceCopy page.

procedure Copy(var actionContext: WebServiceActionContext)

#2 – Expose the procedure using the [ServiceEnabled] attribute

[ServiceEnabled]

#3 – Use the WebServiceActionContext and WebServiceActionResultCode AL types to set the result of the function.

actionContext.SetObjectType(ObjectType::Page);

actionContext.SetObjectId(Page::SalesInvoiceCopy);

actionContext.AddEntityKey(Rec.FIELDNO(Id), ToSalesHeader.Id);

actionContext.SetResultCode(WebServiceActionResultCode::Created);

 

NB: Limitations: “Bound actions cannot be added by extending an existing page that has been exposed as a web service.”

 

Test Web Service – HTTP Request

POST /ODataV4/Company({companyName})/SalesInvoiceCopy({id})/NAV.Copy

Example: Copy an Invoice

{baseurl}/ODataV4/Company(‘CRONUS%20USA%2C%20Inc.’)/SalesInvoiceCopy(‘S-ORD101001’)/NAV.Copy

Source https://docs.microsoft.com/zh-hk/dynamics365/business-central/dev-itpro/developer/devenv-creating-and-interacting-with-odatav4-bound-action

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.