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!