web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :

Bound Actions in Dynamics NAV & Business Central

Roberto Stefanetti Profile Picture Roberto Stefanetti 12,998

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

Comments

*This post is locked for comments

  • ClaudeD Profile Picture ClaudeD 5
    Posted at
    Hi Roberto Thank you it was really helpful, I started to work with bound actions, and I managed to create bound actions to release and reopen orders, thanks to your post. Unfortunately, I tried to create a bound action to print a confirmation order but I can't make it work I work on Business Central 15.5 On-premise I created this procedure [ServiceEnabled] procedure Print(var actionContext: WebServiceActionContext) var DocPrint: Codeunit "Document-Print"; Usage: Option "Order Confirmation","Work Order","Pick Instruction"; begin DocPrint.PrintSalesOrder(Rec, Usage::"Order Confirmation"); actionContext.SetObjectType(ObjectType::Page); actionContext.SetObjectId(Page::SalesOrderList); actionContext.AddEntityKey(Rec.FieldNo("Document Type"), Rec."Document Type"); actionContext.AddEntityKey(Rec.FieldNo("No."), Rec."No."); actionContext.SetResultCode(WebServiceActionResultCode::Updated); end; I publish the page and test the web service {baseurl}/ODataV4/Company('CRONUS%20France%20S.A.')/ListeCdeMultiSoc('Order','1001')/NAV.Print The return status is OK, but there is no printing On the Business Central server, in the Windows Event Viewer, there is a warning : Cannot download print stream to client for report ID 1305 unsupported client type WebServiceClient. Do you know how to create a bound action to print a document, if possible ? Thank you Claude
  • ClaudeD Profile Picture ClaudeD 5
    Posted at
    Hi Roberto Thank you it was really helpful, I started to work with bound actions, and I managed to create bound actions to release and reopen orders, thanks to your post. Unfortunately, I tried to create a bound action to print a confirmation order but I can't make it work I work on Business Central 15.5 On-premise I created this procedure [ServiceEnabled] procedure Print(var actionContext: WebServiceActionContext) var DocPrint: Codeunit "Document-Print"; Usage: Option "Order Confirmation","Work Order","Pick Instruction"; begin DocPrint.PrintSalesOrder(Rec, Usage::"Order Confirmation"); actionContext.SetObjectType(ObjectType::Page); actionContext.SetObjectId(Page::SalesOrderList); actionContext.AddEntityKey(Rec.FieldNo("Document Type"), Rec."Document Type"); actionContext.AddEntityKey(Rec.FieldNo("No."), Rec."No."); actionContext.SetResultCode(WebServiceActionResultCode::Updated); end; I publish the page and test the web service {baseurl}/ODataV4/Company('CRONUS%20France%20S.A.')/ListeCdeMultiSoc('Order','1001')/NAV.Print The return status is OK, but there is no printing On the Business Central server, in the Windows Event Viewer, there is a warning : Cannot download print stream to client for report ID 1305 unsupported client type WebServiceClient. Do you know how to create a bound action to print a document, if possible ? Thank you Claude
  • ClaudeD Profile Picture ClaudeD 5
    Posted at
    Hi Roberto Thank you it was really helpful, I started to work with bound actions, and I managed to create bound actions to release and reopen orders, thanks to your post. Unfortunately, I tried to create a bound action to print a confirmation order but I can't make it work I work on Business Central 15.5 On-premise I created this procedure [ServiceEnabled] procedure Print(var actionContext: WebServiceActionContext) var DocPrint: Codeunit "Document-Print"; Usage: Option "Order Confirmation","Work Order","Pick Instruction"; begin DocPrint.PrintSalesOrder(Rec, Usage::"Order Confirmation"); actionContext.SetObjectType(ObjectType::Page); actionContext.SetObjectId(Page::SalesOrderList); actionContext.AddEntityKey(Rec.FieldNo("Document Type"), Rec."Document Type"); actionContext.AddEntityKey(Rec.FieldNo("No."), Rec."No."); actionContext.SetResultCode(WebServiceActionResultCode::Updated); end; I publish the page and test the web service {baseurl}/ODataV4/Company('CRONUS%20France%20S.A.')/ListeCdeMultiSoc('Order','1001')/NAV.Print The return status is OK, but there is no printing On the Business Central server, in the Windows Event Viewer, there is a warning : Cannot download print stream to client for report ID 1305 unsupported client type WebServiceClient. Do you know how to create a bound action to print a document, if possible ? Thank you Claude
  • Community Member Profile Picture Community Member
    Posted at
    I need to post a sales order from dynamic 365 business central v15 cloud version via API. It is mentioned in above post - Example: http://:/ODataV4/Company(‘CRONUS%20International%20Ltd.’)/SalesOrders(,)/NAV.Post Bound Action In this case we are calling the “Post function” existing in “Sales Order” page. How would I form the url for cloud version?