Senden externer Dokumente

Möchten Sie die App zum Senden externer Belege über Business Central nutzen, da Sie bspw. auf die Kontaktdaten aus Business Central zugreifen möchten. Können Sie dies mit einem einfachen Funktionsaufruf selbst implementieren.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
codeunit 50200 EPostApiExt
{
    trigger OnRun()
    var
        Contact: Record Contact;
        DocumentAttachment: Record "Document Attachment";
        EPostAPI: Codeunit "BEL365 E-POST Api";
        LetterFileTempBlob: Codeunit "Temp Blob";
        ContactDataJson: JsonObject;
        DocNo: Code[20];
        DocumentTypes: Enum "BEL365 Document Types";
        OStream: OutStream;
    begin
        // Fill document no and document type if letter document is linked to an existing document within Business Central, otherwise leave this empty
        DocNo := '10000';
        DocumentTypes := DocumentTypes::"Posted Sales Invoice";

        // Fill TempBlob Codeunit with a document that was previsouly imported to Business Central
        DocumentAttachment.SetRange("Table ID", Database::"Sales Invoice Header");
        DocumentAttachment.SetRange("No.", DocNo);
        if DocumentAttachment.FindFirst() then begin
            LetterFileTempBlob.CreateOutStream(OStream);
            DocumentAttachment."Document Reference ID".ExportStream(OStream);
        end;

        // If no contact exists in Business Central fill json object with contact data, otherwise leave this empty
        ContactDataJson.Add('CompanyName', 'Testfirma');
        ContactDataJson.Add('ContactName', 'Testperson');
        ContactDataJson.Add('Address', 'TeststraĂźe');
        ContactDataJson.Add('PostCode', '12345');
        ContactDataJson.Add('City', 'Teststadt');
        ContactDataJson.Add('Country', 'Ă–STERREICH'); // Not neccessary if recipient residents within Germany

        // Call the function to start the sending process of the document with previously filled parameters
        EPostAPI.SendLetter(Contact, '10000', Enum::"BEL365 Document Types"::"Posted Purchase Invoice", LetterFileTempBlob, ContactDataJson);
    end;
}