Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Modifying Ship-to Code on Sales Orders

(1) ShareShare
ReportReport
Posted on by 33
Hi,
 
I have been trying to find a way to POST to a sales order with the standard API to change the Ship-to code.
 
With the standard /salesOrder endpoint there is no field to allow Ship-to Codes to be changed from the generated default.
 
I have exposed the endpoint for /APIV2 - Sales Shipments/ via the Web Services in Dynamics, and it actually has the Ship-to Code field present in the response. However, you can't POST to the endpoint to change the Ship-to Code because it doesn't support insert, even with If-Match set. 
 
I have attempted to make an AL page extension just extending the Sales Order Shipment page to make Editable = true. Didn't work though, and after looking at the official documentation looks like you cannot change a non-editable page to editable with custom extensions. Tried setting InsertAllowed = true as well but it doesn't work for page extensions.
 
Is there any way to change the Ship-to Code, preferably with just using a different standard API endpoint? If not, how would I go about making an extension with AL. I am not very experienced with AL so a bit of break down of how to do it would be great :)
 
 
  • Verified answer
    jessb101 Profile Picture
    33 on at
    Modifying Ship-to Code on Sales Orders
    Hello,
     
    I have figured out how to change the Ship-to Codes like I needed. Thank you!
     
    I went with the route of using a custom API like Saurav suggested.
     
    After making the custom API, I figured out the issue I ran into with the standard API was that the standard API endpoint for the sales shipments did not return the id for the sales shipment record, therefore I could not POST/PATCH an updated Ship-to Code to a record.
     
    In my custom API, I changed the response to include that id so the Ship-to code could be updated.
     
    Here is what I did:
     
    Using the follow code below I created a custom API based off of the Sales Order Shipment table.
     
    I would HIGHLY suggest you use VS Code with the AL extension developed by Microsoft and the AZ AL Tools extension as it make developing with AL much easier with autofill.
     
    To save someone out there some frustration - some of the tables have different reference names than their SourceTable names. In the UI, the table I used is referred to as 'Sales Order Shipping' or 'APIV2 - Sales Shipments' from the Web Service, but both are referencing the same SourceTable of 'Sales Header' as you can see below.
     
    If you ever need to find the SourceTable name of a different table, in the UI go to your desired table, then click on the '?' at the top of the page, then 'Help and Support', scroll down on the page it opens up and click on 'Inspect pages and data'. A panel will then pop up on the right side and say what SourceTable it is along with the table number.
     
    namespace Microsoft.API.V2;
    
    using Microsoft.Integration.Entity;
    using Microsoft.Sales.Document;
    using Microsoft.Sales.Customer;
    using Microsoft.Finance.Currency;
    using Microsoft.Foundation.PaymentTerms;
    using Microsoft.Foundation.Shipping;
    using Microsoft.Integration.Graph;
    using Microsoft.Sales.History;
    using Microsoft.Sales.Posting;
    using Microsoft.Utilities;
    using Microsoft.API;
    page 50102 "API Sales Order Test"
    {
        PageType = API;
    
        APIVersion = 'v1.0';
        APIPublisher = 'COMPANY';
        APIGroup = 'COMPANYGROUP';
    
        EntityCaption = 'SalesOrderTest2';
        EntitySetCaption = 'SalesOrdersTest2';
        EntityName = 'salesOrderTest2';
        EntitySetName = 'salesOrdersTest2';
    
        ODataKeyFields = SystemId;
        SourceTable = "Sales Header";
    
        Extensible = false;
        DelayedInsert = true;
    
        layout
        {
            area(content)
            {
                repeater(Group)
                {
                    field(id; Rec.SystemId)
                    {
                        Caption = 'Id';
                        Editable = false;
                    }
    
                    field(number; Rec."No.")
                    {
                        Caption = 'No.';
                        
                    }
    
                    field(Ship_to_Code; Rec."Ship-to Code")
                    {
                        Caption = 'Ship-to Code';
                    }
                    
                }
                
            }
        }
    }
     
    There are many different fields you can add to be returned, use the autofill feature with the AL extensions to see what can be returned.
     
    Upload this to your Dynamics environment, and then you can call to it via endpoint. The endpoint is formed https://api.businesscentral.dynamics.com/v2.0/<ENVIRONMENT NAME>/api/<API PUBLISHER>/<APIGROUP>/v1.0/companies(<COMPANY ID>)/<ENTITYSETNAME>
     
    Calling to that endpoint will return every record, so once you find the id returned from a record you want to update, form the endpoint like so https://api.businesscentral.dynamics.com/v2.0/<ENVIRONMENT NAME>/api/<API PUBLISHER>/<APIGROUP>/v1.0/companies(<COMPANY ID>)/<ENTITYSETNAME>(<id>)
     
    To update the Ship-to Code field, patch to the endpoint with the record id, JSON body, and make sure to set the header with If-Match: * and Content-type : application/json as well as pass in the OAUTH token.
     
    Hope this helps!
     
  • Suggested answer
    YUN ZHU Profile Picture
    84,467 Super User 2025 Season 1 on at
    Modifying Ship-to Code on Sales Orders
    Hi, I think you can try Bound Actions.
    Dynamics 365 Business Central: How to use Standard/Custom API Bound Actions
     
    Hope this helps.
    Thanks.
    ZHU
  • Suggested answer
    Saurav.Dhyani Profile Picture
    14,316 Super User 2025 Season 1 on at
    Modifying Ship-to Code on Sales Orders
    Hi,
     
    You will have to create a custom API Endpoint to add that field in API Page.
     
    Regards,
    Saurav Dhyani
  • Gerardo Rentería García Profile Picture
    19,829 Most Valuable Professional on at
    Modifying Ship-to Code on Sales Orders
    Hi
    Some posted documents can be modified, complying with certain forms.
    Likewise, not all fields can be changed. I hope this information helps you and gives you some ideas.
    BR
    GR

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 1,452

#2
YUN ZHU Profile Picture

YUN ZHU 1,313 Super User 2025 Season 1

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 1,083 Most Valuable Professional

Featured topics

Product updates

Dynamics 365 release plans