Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

Posted on by

Hi!

I would like to know if there is a way to trigger the Posting -> Post -> Ship action (no invoice) for Sales Order using the OData Web Services, SOAP Web Services or API Endpoints

pastedimage1632849270594v1.png

I already saw this bound actions but i would like to make the same without the invoice stuff.

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/resources/dynamics_salesorder#bound-actions

pastedimage1632849644568v2.png

King regards!

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 20,991 Super User on at
    RE: Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

    Please go through the link and try to understand the process.

  • agaonkar Profile Picture
    agaonkar 25 on at
    RE: Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

    Thanks for the link. But I am not able to understand anything.

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 20,991 Super User on at
    RE: Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

    Please go through the below link:

    community.dynamics.com/.../posting-invoices-using-apis

  • agaonkar Profile Picture
    agaonkar 25 on at
    RE: Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

    I tried the following:

    api.businesscentral.dynamics.com/.../Microsoft.NAV.shipAndInvoice

    where e75cee00-b718-ed11-90eb-000d3a54b3bc is my salesorder id and the request body is

    {

       "number": "S-ORD101011"

    }

    Response is:

    {

       "error": {

           "code": "BadRequest",

           "message": "One or more errors occurred.  CorrelationId:  2a39d66e-3719-4980-be0c-cfcb326dc36c."

       }

    }

    Is there anything wrong?

  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 20,991 Super User on at
    RE: Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

    You have to supply sales order no. filter within your api to perform the Ship and invoice action.

    Thanks.

  • agaonkar Profile Picture
    agaonkar 25 on at
    RE: Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

    Hi there,

    Could you please help me with the request body for the API call

    api.businesscentral.dynamics.com/.../Microsoft.NAV.shipAndInvoice

    Currently I am not supplying anything and it says 

    {
        "error": {
            "code""Application_DialogException",
            "message""Please add at least one line item to the estimate.  CorrelationId:  98d53cd2-b0d3-4962-ab8f-5be785418ff8."
        }
    }
  • Samantha73 Profile Picture
    Samantha73 2,195 on at
    RE: Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

    Awesome ...Not a lot of info out there on APIs and some are not there to start with like AP credits...good thing is you can create bound actions or unbound. If performance is key unbound is recommended

  • Suggested answer
    jcdlm Profile Picture
    jcdlm on at
    RE: Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

    Finally I solved my problem,

    First of all, I follow this guide to configure AL environment in Visual Studio Code

    docs.microsoft.com/.../devenv-get-started

    Then, downloaded this github repo

    github.com/.../ALAppExtensions

    In the APIV2SalesOrders.Page.al file, I found shipAndInvoice procedure, so I modified it as Samantha said and added the new code to my custom page.

    Then I published as a Web Service and now Im able to trigger this actions using OdataV4

    Hope it helps for someone with same needed.

    Kind regards!

  • jcdlm Profile Picture
    jcdlm on at
    RE: Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

    Hello Samantha,

    Thanks for answering.

    Where did u get that code from?

  • Verified answer
    Samantha73 Profile Picture
    Samantha73 2,195 on at
    RE: Posting Ship Sales Order with OData WS / SOAP WS / API(v2.0)

    You can copy existing API and create your own. In the new API, comment out below code and create new procedure or rename existing to something like shipOnly(not a requirement just best practise):

       local procedure PostWithShipAndInvoice(var SalesHeader: Record "Sales Header"; var SalesInvoiceHeader: Record "Sales Invoice Header")

       var

           DummyO365SalesDocument: Record "O365 Sales Document";

           LinesInstructionMgt: Codeunit "Lines Instruction Mgt.";

           O365SendResendInvoice: Codeunit "O365 Send + Resend Invoice";

           OrderNo: Code[20];

           OrderNoSeries: Code[20];

       begin

           O365SendResendInvoice.CheckDocumentIfNoItemsExists(SalesHeader, false, DummyO365SalesDocument);

           LinesInstructionMgt.SalesCheckAllLinesHaveQuantityAssigned(SalesHeader);

           OrderNo := SalesHeader."No.";

           OrderNoSeries := SalesHeader."No. Series";

           SalesHeader.Ship := true;

           //SalesHeader.Invoice := true;//

           SalesHeader.SendToPosting(Codeunit::"Sales-Post");

           SalesInvoiceHeader.SetCurrentKey("Order No.");

           SalesInvoiceHeader.SetRange("Pre-Assigned No. Series", '');

           SalesInvoiceHeader.SetRange("Order No. Series", OrderNoSeries);

           SalesInvoiceHeader.SetRange("Order No.", OrderNo);

           SalesInvoiceHeader.FindFirst();

       end;

    Note: You also need to change few other bits since API looking for created invoice number so find that code but above works as is though u get a error response but order is shiped

    /salesOrders(4bac2cec-1821-ec11-8f46-00224810896b)/Microsoft.NAV.shipOnly

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,513 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,862 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans