Working with OData Bound Actions - CloudFronts

Working with OData Bound Actions

Introduction

OData Bound Actions allows us to perform logic in Business Central by hitting specific end points.

We can also pass in parameters and get results in response. It’s very similar to using Azure Functions but is natively built into Business Central at no extra cost!

In this example, we’ll be returns the Base64 version of an Image of a Customer, we will also see how to get the Image for any other customer as well.

Pre-requisites

Business Central OnCloud/OnPrem

References

Configuration

  • OData Bound Actions are written on Pages or API – Pages that you are declaring as Web Services.
  • In this example below, I’ve created a simple Customer Page with a few fields and kept the OData key field as the “No.” field. I’ve also defined this as a Web Service in Business Central.
     
  • To create a OData Bound Action, we create a Global Procedure with the Service Enabled decorator.
  • In this procedure, we have to create a WebServiceActionContext variable and set the “ObjectType”, “ObjectID” and Keys that we are using for this Web Service, which is “No.” in this case, after our processing is done we also need to set the “Result Code” for this request.
     
  • In the above piece of code, I’ve written simple logic which converts the content of a Media Data Type (Image field) to Base64 Text and returns it.
    In Post-Man if you check of the metadata, you’ll be able to see this action defined in the metadata.
     
  • Now, it’s time to test out OData Bound Action!
    To call the OData Bound Action, we need to be working with a single record. So we specify the “No.” field to identify a single record.
     
  • Now, we append our procedure name as “NAV.[Procedure Name]” and make a POST request.
     
  • If we put this Base64 through a Base64 to File Converter, we can see that the original data is recovered.
     
  • Now, we create a new procedure, which will take the System ID as a parameter and return the Image data for that Customer Record.
     

  1.  
  • If you want to pass the parameters to the OData Bound Actions, you have to do it as the Body of the Request.
     

Conclusion:

P.S. I’ve tried but it seems polymorphism doesn’t work with this.

I hope this was insightful and a quick start on how to write OData Bound Actions.

Happy coding!


Share Story :

Secured By miniOrange