Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Suggested answer

Post Transfer Order API

Posted on by 34

I want to create API of method behind post button of transfer order , I check out and find this codeunit 

codeunit 5706 "TransferOrder-Post (Yes/No)"  so anybody knows how to create it?
Code Unit code is given below:
codeunit 5706 "TransferOrder-Post (Yes/No)"
{
    TableNo = "Transfer Header";

    trigger OnRun()
    begin
        TransHeader.Copy(Rec);
        Code;
        Rec := TransHeader;
    end;

    var
        Text000: Label '&Ship,&Receive';
        TransHeader: Record "Transfer Header";

    local procedure "Code"()
    var
        InvtSetup: Record "Inventory Setup";
        TransLine: Record "Transfer Line";
        TransferPostShipment: Codeunit "TransferOrder-Post Shipment";
        TransferPostReceipt: Codeunit "TransferOrder-Post Receipt";
        TransferOrderPostTransfer: Codeunit "TransferOrder-Post Transfer";
        DefaultNumber: Integer;
        Selection: Option " ",Shipment,Receipt;
        IsHandled: Boolean;
    begin
        OnBeforePost(TransHeader, IsHandled);
        if IsHandled then
            exit;

        InvtSetup.Get();

        TransLine.SetRange("Document No.", TransHeader."No.");
        if TransLine.Find('-') then
            repeat
                if (TransLine."Quantity Shipped" < TransLine.Quantity) and
                    (DefaultNumber = 0)
                then
                    DefaultNumber := 1;
                if (TransLine."Quantity Received" < TransLine.Quantity) and
                    (DefaultNumber = 0)
                then
                    DefaultNumber := 2;
            until (TransLine.Next() = 0) or (DefaultNumber > 0);
       
        IsHandled := false;
        OnCodeOnBeforePostTransferOrder(TransHeader, DefaultNumber, Selection, IsHandled);
        if not IsHandled then
            if TransHeader."Direct Transfer" then
                case InvtSetup."Direct Transfer Posting" of
                    InvtSetup."Direct Transfer Posting"::"Receipt and Shipment":
                        begin
                            TransferPostShipment.Run(TransHeader);
                            TransferPostReceipt.Run(TransHeader);
                        end;
                    InvtSetup."Direct Transfer Posting"::"Direct Transfer":
                        TransferOrderPostTransfer.Run(TransHeader);
                end
            else begin
                if DefaultNumber = 0 then
                    DefaultNumber := 1;
                Selection := StrMenu(Text000, DefaultNumber);
                case Selection of
                    0:
                        exit;
                    Selection::Shipment:
                        TransferPostShipment.Run(TransHeader);
                    Selection::Receipt:
                        TransferPostReceipt.Run(TransHeader);
                end;
            end;

        OnAfterPost(TransHeader, Selection);
    end;

    [IntegrationEvent(false, false)]
    local procedure OnAfterPost(var TransHeader: Record "Transfer Header"; Selection: Option " ",Shipment,Receipt)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnBeforePost(var TransHeader: Record "Transfer Header"; var IsHandled: Boolean)
    begin
    end;

    [IntegrationEvent(false, false)]
    local procedure OnCodeOnBeforePostTransferOrder(var TransHeader: Record "Transfer Header"; var DefaultNumber: Integer; var Selection: Option; var IsHandled: Boolean)
    begin
    end;
}
Categories:
  • Suggested answer
    DAnny3211 Profile Picture
    DAnny3211 9,217 Moderator on at

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 228,647 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans