How to fixed Sales Order OData V4 Ship-To / Bill-To Errors in Business Central

How to Fix Sales Order OData V4 Ship-To / Bill-To Errors in Business Central

When integrating with Microsoft Dynamics 365 Business Central through the OData V4 API, I ran into a problem while creating Sales Orders with Ship-To addresses.

Sales Orders without Ship-To or Bill-To information were created without any issues. However, as soon as I tried to include a Ship-To address as an Alternative Shipping Address, the API returned errors. After some investigation, the solution turned out to be a very small but important change in the page extension.

Problem

I was posting a Sales Order using the OData API and included Ship-To fields in the payload:

{ "Document_Type": "Order", "Sell_to_Customer_No": "10000", "ShipToOptions": "Alternate Shipping Address", "Ship_to_Code": "0009" }

Instead of processing the request, Business Central returned errors such as:

  • Form.RunModal is not allowed in write transactions

  • Validation failures on Ship-To fields

This clearly indicated that the API was not recognizing the Ship-To field correctly.

Root Cause

When I reviewed the Sales Order Card page extension, I found two issues:

  1. The default code was attempting to open a page during the write transaction. Since API requests run as background write transactions, any call that opens a page or modal dialog (for example, Form.RunModal) is not allowed. This was the reason behind the write transaction error.

  2. The ShipToOptions field is a protected variable in Business Central. Because of this, it cannot be directly exposed to OData requests.

To make it usable in API requests, I added a new field on the page extension that referenced the base variable:

field(ShipToOptionsnew; ShipToOptions)

{

    ApplicationArea = All;

}

By exposing this new field (ShipToOptionsnew) at the page level, I was able to pass the value successfully through the OData API.

The Fix

Once I updated my API request to use the correct field name (ShipToOptionsnew) and set it before providing the Ship-To details, the Sales Order was created successfully.

Here’s the working payload:

{

  "Document_Type": "Order",

  "Sell_to_Customer_No": "10000",

  "ShipToOptionsnew": "Alternate Shipping Address",

  "Ship_to_Code": "0009"

}

This small change ensured that Business Central recognized the request correctly and accepted the Alternative Shipping Address details.


Key Takeaways

  • Always confirm whether fields are standard or have been extended/renamed in your environment.

  • If you encounter validation errors when posting Ship-To or Bill-To details, check the Page Extension code to see how fields are defined.

  • In this case, replacing ShipToOptions with ShipToOptionsnew resolved the issue immediately.

  • Before building integration logic, run a GET request on an existing Sales Order. This will show you the exact field names your system exposes through OData.

By identifying the correct field name and adjusting the request accordingly, I was able to resolve the Ship-To error and successfully create Sales Orders via OData V4.

Thank you for your time,
Dharmendra Chavda

Comments

Popular posts from this blog

Data Upload into CRM from Excel Using Power Automate

Run a Dynamics 365 Plugin from JavaScript on Button Click

Update a Lookup Field value using PowerAutomate