Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

API - Ship-to Address

Posted on by 41
Hi All,
I have an API page for Ship-to adress (Customer) but i cant seem to modify records.

Here's my code
codeunit 50108 "Ship To Address"
{
    procedure UpdateShipToAddress(
            CustomerNo: Code[20];
            Code: Code[20];
            ShipName: Text[100];
            Address: Text[100];
            Address2: Text[50];
            City: Code[20];
            PhoneNo: Text[50];
            CountryRegion: Code[10];
            PostCode: Code[20];
            County: Text[30];
            ShipToLabel: Text[30];
            BranchNo: Text[30])
    var
        ShipToAddressRec: Record "Ship-to Address";
    begin
        if ShipToAddressRec.Get(CustomerNo, Code) then begin
            ShipToAddressRec.Name := ShipName;
            ShipToAddressRec.Address := Address;
            ShipToAddressRec."Address 2" := Address2;
            ShipToAddressRec.City := City;
            ShipToAddressRec."Phone No." := PhoneNo;
            ShipToAddressRec."Country/Region Code" := CountryRegion;
            ShipToAddressRec."Post Code" := PostCode;
            ShipToAddressRec.County := County;
            ShipToAddressRec."Ship to Label" := ShipToLabel;
            ShipToAddressRec."Branch No" := BranchNo;
            ShipToAddressRec.Modify();
        end else
            Error('Ship-to Address not found for Customer No. %1 and Code %2', CustomerNo, Code);
    end;
 
    [ServiceEnabled]
    procedure PostUpdateShipToAddress(
        CustomerNo: Code[20];
        Code: Code[20];
        ShipName: Text[100];
        Address: Text[100];
        Address2: Text[50];
        City: Code[20];
        PhoneNo: Text[50];
        CountryRegion: Code[10];
        PostCode: Code[20];
        County: Text[30];
        ShipToLabel: Text[30];
        BranchNo: Text[30])
    begin
        UpdateShipToAddress(CustomerNo, Code, ShipName, Address, Address2, City, PhoneNo, CountryRegion, PostCode, County, ShipToLabel, BranchNo);
    end;
}
******************PAGE***************************
page 50108 "CPT Ship To Address"
{
    PageType = API;
    APIPublisher = 'RS';
    APIGroup = 'Shipping';
    APIVersion = 'v2.0';
    EntitySetName = 'shiptoaddress';
    EntityName = 'shiptoaddress';
    EntitySetCaption = 'shiptoaddress';
    EntityCaption = 'shiptoaddress';
    ChangeTrackingAllowed = true;
    DelayedInsert = true;
    ODataKeyFields = "Customer No.";
    SourceTable = "Ship-to Address";
    Extensible = true;
 
    layout
    {
        area(content)
        {
            repeater(Group)
            {
                field(CustNo; rec."Customer No.")
                {
                    Caption = 'Customer No';
                    ApplicationArea = all;
                }
                field(ShipCode; Rec.Code)
                {
                    Caption = 'Code';
                    ApplicationArea = all;
                }
 
                field(ShipName; Rec.Name)
                {
                    Caption = 'Name';
                    ApplicationArea = all;
                }
                field(Address; Rec.Address)
                {
                    Caption = 'Address';
                    ApplicationArea = all;
                }
                field("Address2"; Rec."Address 2")
                {
                    Caption = 'Address 2';
                    ApplicationArea = all;
                }
                field(City; Rec.City)
                {
                    Caption = 'City';
                    ApplicationArea = All;
                }
                field("PhoneNo"; Rec."Phone No.")
                {
                    Caption = 'PhoneNo';
                    ApplicationArea = all;
                }
                field("CountryRegion"; Rec."Country/Region Code")
                {
                    Caption = 'Cpuntry/Region Code';
                    ApplicationArea = all;
                }
                field(PostCode; Rec."Post Code")
                {
                    Caption = 'Post Code';
                    ApplicationArea = all;
                }
                field(County; Rec.County)
                {
                    Caption = 'County';
                    ApplicationArea = all;
                }
                field(ShipToLabel; Rec."Ship To Label")
                {
                    Caption = 'Ship To Label';
                    ApplicationArea = all;
                }
                field("BranchNo"; Rec."Branch No")
                {
                    Caption = 'Branch No';
                    ApplicationArea = All;
                }
 
            }
        }
    }
}
  • Rajiv Sewsarran Profile Picture
    Rajiv Sewsarran 41 on at
    API - Ship-to Address
    YUN ZHU
    Sorry i didn't realize my message got cut off - these are the two different approaches i tried.

     
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 68,395 Super User 2024 Season 2 on at
    API - Ship-to Address
    As mentioned in my post, you are trying to modify multiple records at the same time, which will cause this problem.
    But I don't quite understand your approach. If you publish the codeunit as a bound action in the web service, the API page below is unnecessary.
    If you use the API page below to update data, the codeunit above is useless.
     
    Thanks.
    ZHU
  • Suggested answer
    gdrenteria Profile Picture
    gdrenteria 8,566 Most Valuable Professional on at
  • Netjacker2097 Profile Picture
    Netjacker2097 256 on at
    API - Ship-to Address
    Hi,
     
    can you please show the the Body what you are patching?
     
    Thanks,
    M
  • Rajiv Sewsarran Profile Picture
    Rajiv Sewsarran 41 on at
    API - Ship-to Address
    response from postman
    {
        "error": {
            "code": "BadRequest_MethodNotAllowed",
            "message": "'PATCH' requests for 'CPTShipToAddress' of EdmType 'Collection' are not allowed within Dynamics 365 Business Central OData web services."
        }
    }

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,252 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,089 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans