7. Februar 2024 14:47
8. Februar 2024 00:27
OnBeforePrintDocument(TempReportSelections, IsGUI, RecVarToPrint, IsHandled);
if not IsHandled then
      REPORT.RunModal(TempReportSelections."Report ID", IsGUI, false, RecVarToPrint);
OnSendEmailDirectlyOnBeforeSaveReportAsPDFInTempBlob(TempAttachReportSelections, DocumentRecord, ReportUsage, TempBlob, IsHandled);
if not IsHandled then
     SaveReportAsPDFInTempBlob(TempBlob, "Report ID", DocumentRecord, "Custom Report Layout Code", ReportUsage);
[EventSubscriber(ObjectType::Table, database::"Report Selections", 'OnBeforePrintDocument', '', true, true)]
    local procedure OnBeforePrintDocument(TempReportSelections: Record "Report Selections" temporary; IsGUI: Boolean; var RecVarToPrint: Variant; var IsHandled: Boolean)
    begin
        setSelectedLayout(RecVarToPrint);
    end;
    [EventSubscriber(ObjectType::Table, database::"Report Selections", 'OnSendEmailDirectlyOnBeforeSaveReportAsPDFInTempBlob', '', true, true)]
    local procedure OnSendEmailDirectlyOnBeforeSaveReportAsPDFInTempBlob(ReportSelection: Record "Report Selections"; RecordVariant: Variant; ReportUsage: Enum "Report Selection Usage"; var TempBlob: Codeunit "Temp Blob"; var IsHandled: Boolean)
    begin
        setSelectedLayout(RecordVariant);
    end;
    local procedure setSelectedLayout(RecordVariant: Variant)
    var
        DesigntimeReportSelection: Codeunit "Design-time Report Selection";
        DataTypeManagement: Codeunit "Data Type Management";
        RecordRef: RecordRef;
        FieldRef: FieldRef;
        LayoutName: Text[250];
    begin
        RecordRef.GetTable(RecordVariant);
        case RecordRef.Number of
            database::"Sales Header":
                begin
                    if DataTypeManagement.FindFieldByName(RecordRef, FieldRef, 'elf_Report Layout Name') then begin
                        LayoutName := FieldRef.Value;
                        if LayoutName <> '' then begin
                            DesigntimeReportSelection.ClearLayoutSelection();
                            DesigntimeReportSelection.SetSelectedLayout(LayoutName);
                        end;
                    end;
                end;
        end;
    end;