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:
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:
-
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. -
The
ShipToOptions
field is a protected variable in Business Central. Because of this, it cannot be directly exposed to OData requests.
field(ShipToOptionsnew; ShipToOptions)
{
ApplicationArea = All;
}
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"
}
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.
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.
Thank you for your time,
Dharmendra Chavda
Comments
Post a Comment