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

6 thoughts on “Bound Actions in Dynamics NAV & Business Central

  • 22 July 2019 at 6:38 AM
    Permalink

    Hi Roberto, followed the specified steps, but I can’t seem to make it work for me on Dynamics 365 Business Central. Am I missing something?

    I got a “No HTTP resource was found that matches the request URI” on the After Bound Actions introduction…

    And a “No HTTP resource was found that matches the request URI” on Declaring the OData bound action

    Reply
    • 27 September 2019 at 8:53 PM
      Permalink

      Hello Allone,

      Did you find any solution for this issue?

      I am getting the sales invoice data If I use below URL

      /ODataV4/Company(‘CRONUS%20USA%2C%20Inc.’)/SalesInvoiceCopy(‘S-ORD101001’)

      but receiving “No HTTP resource was found” error when adding “NAV.Copy” action segment like below

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

      I am sure that I have implemented the same code shared in the source link provided in this post.

      let me know If I miss any thing here

      Reply
      • 18 May 2021 at 4:27 PM
        Permalink

        Did anybody already solve this issue?
        I have exactly the same problem here.

        Reply
  • 27 September 2019 at 8:55 PM
    Permalink

    Hello Roberto,

    Any change in the action segment call.

    I have referred BC development document it says action segment should be “Microsoft.NAV.Copy”

    I tried that also but getting the same error

    please help.

    Reply
  • 11 September 2021 at 8:30 AM
    Permalink

    Hey,

    Take a look at page 5475 “Sales Invoice Entity” for details on how to use Bound Actions.

    Also you can achieve the same thing without the ActionContext fuss. Take a look at this guide: https://docs.microsoft.com/en-us/dynamics-nav/walkthrough-creating-and-interacting-odata-v4-bound-action

    VERY IMPORTANT: Make sure when you are sending the request, the request body json keys start with a small letter. To make it easy to remember ensure that your parameter names in the NAV function begin with a small letter. For example: employeeNo instead of EmployeeNo. If you send a request json body with the key beginning a capital letter you will get an error saying: BadRequest: Exception of type ‘Microsoft.Dynamics.Nav.Service.OData.NavODataBadRequestException’ was thrown. CorrelationId: 6ca2a4e1-8e37-4c6b-b542-6813bcf61d74.

    So don’t use: { LineNo: 30 }, use { lineNo: 30 } as your request body.

    Reply
  • 27 July 2022 at 4:27 PM
    Permalink

    Does NTLM realy works with bound / unbound actions?
    User / Password works without any problem.

    NTLM with Bound actions gives me:
    Status 500Object reference not set to an instance of an object.
    Unbound: 500Index was out of range

    Did u tested it?
    Do you have any ideas?

    Best Regards,
    Michael

    Reply

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.