Ga naar inhoud

Multimail functionaliteit implementeren

De implementatie van de Multimail-functionaliteit binnen de Document Dispatch kan worden uitgebreid naar extra pagina's. Hieronder staat een voorbeeld van hoe je de Multimail functie kunt integreren. Deze specifieke implementatie is op maat gemaakt voor de pagina die is gekoppeld aan het record Koopfactuur koptekst. Let op de gemarkeerde regels in het codefragment; deze regels moeten worden aangepast aan het specifieke record.

AL
action(SIM_EDS_Multimail)
{
    Caption = 'Multimail';
    ToolTip = 'This button sends all marked entries via email. The entries will be sent in case an active dispatch profile is configured for the respective entries.';
    Ellipsis = true;
    Image = SendTo;
    ApplicationArea = All;

    trigger OnAction()
    var
        LocalRecordSIMEDSSetup: Record "SIM_EDS Setup";
        LocalRecordSalesInvoiceHeader: Record "Sales Invoice Header";
        TempLocalRecordSIMEDSRecord: Record "SIM_EDS Record" temporary;
        TempLocalRecordSIMEDSBusinessPartner: Record "SIM_EDS Business Partner" temporary;
        TempLocalRecordSIMEDSDynamicBP: Record "SIM_EDS Dynamic BP" temporary;
        LocalRecordSIMEDSMultimailPreview: Record "SIM_EDS Multimail Preview";
        LocalCodeunitSIMEDSMgt: Codeunit "SIM_EDS Mgt";
        LocalCodeunitSIMEDSQueueMgt: Codeunit "SIM_EDS Queue Mgt";
        LocalCodeunitSIMEDSSI: Codeunit "SIM_EDS SI";
        LocalCodeunitSIMEDSMailMgt: Codeunit "SIM_EDS Mail Mgt";
        LocalRecordRef: RecordRef;
        LocalDynamicBusinessMappingExistsBoolean: Boolean;
        LocalNotAllEntriesPossible: Boolean;
        LocalExtendedBusinessMappingExistsBoolean: Boolean;
        LocalEntryNoListOfInteger: List of [Integer];
    begin
        LocalRecordSIMEDSMultimailPreview.DeleteAll();
        LocalCodeunitSIMEDSSI.ClearListsForMultimail();

        CurrPage.SetSelectionFilter(LocalRecordSalesInvoiceHeader);
        if not LocalRecordSIMEDSSetup.Get() then exit;

        if LocalRecordSalesInvoiceHeader.FindSet() then
            repeat
                LocalRecordRef.GetTable(LocalRecordSalesInvoiceHeader);

                LocalCodeunitSIMEDSMgt.GetRecords(LocalRecordRef, TempLocalRecordSIMEDSRecord);

                LocalCodeunitSIMEDSMgt.GetRecordAssignedData(
                    LocalRecordRef,
                    true,
                    LocalDynamicBusinessMappingExistsBoolean,
                    LocalExtendedBusinessMappingExistsBoolean,
                    TempLocalRecordSIMEDSRecord,
                    TempLocalRecordSIMEDSBusinessPartner,
                    TempLocalRecordSIMEDSDynamicBP,
                    true);

                TempLocalRecordSIMEDSRecord.SetRange("Table No.", LocalRecordRef.Number());
                TempLocalRecordSIMEDSRecord.SetRange("Output Type", TempLocalRecordSIMEDSRecord."Output Type"::"Mail");
                if not TempLocalRecordSIMEDSRecord.IsEmpty then
                    LocalCodeunitSIMEDSQueueMgt.SendEDS(LocalRecordRef, true, false, '', false, false, true)
                else begin
                    LocalNotAllEntriesPossible := true;
                    LocalCodeunitSIMEDSSI.AddFailedMultimailRecordToList(LocalRecordSalesInvoiceHeader.RecordId);
                    LocalCodeunitSIMEDSSI.AddFailedMultimailEntryNoToList(0);
                end;
            until LocalRecordSalesInvoiceHeader.Next() = 0;

        LocalEntryNoListOfInteger := LocalCodeunitSIMEDSSI.GetEntryNoList();

        if LocalEntryNoListOfInteger.Count <> 0 then begin
            if LocalCodeunitSIMEDSMgt.CheckCreatedMultimailEntries(LocalEntryNoListOfInteger) then begin
                LocalCodeunitSIMEDSMailMgt.SetMultimailDocuments(true);
                LocalCodeunitSIMEDSMailMgt.CheckEmailFilled(LocalEntryNoListOfInteger);
                LocalCodeunitSIMEDSMgt.Multimail(LocalEntryNoListOfInteger);
            end;
            if LocalNotAllEntriesPossible and not LocalRecordSIMEDSSetup."Use Multimail Preview" then
                Message(GlobalSelectedEnrtiesMultimailNotPossibleLabelTxt);
        end else
            Message(GlobalMultimailNotPossibleLabelMsg);

        LocalCodeunitSIMEDSSI.ClearListsForMultimail();

        LocalRecordSIMEDSMultimailPreview.Reset();
        LocalRecordSIMEDSMultimailPreview.DeleteAll();
    end;
}