Skip to content

[Event Request] Table 5062 "Attachment".ImportAttachmentFromServerFile #28890

@fridrichovsky

Description

@fridrichovsky

Why do you need this change?

Please add new event

[Scope('OnPrem')]
    procedure ImportAttachmentFromServerFile(ImportFromFile: Text; IsTemporary: Boolean; Overwrite: Boolean) Result: Boolean
    var
        TempBlob: Codeunit "Temp Blob";
        IsHandled: Boolean;
        FileExt: Text[250];
    begin
        IsHandled := false;
        OnBeforeImportAttachmentFromServerFile(Rec, ImportFromFile, Result, IsHandled);
        if IsHandled then
            exit(Result);

        if IsTemporary then begin
            ImportTemporaryAttachmentFromServerFile(ImportFromFile);
            exit(true);
        end;

        if not Overwrite then
            TestField("Read Only", false);

        RMSetup.Get();
        if RMSetup."Attachment Storage Type" = RMSetup."Attachment Storage Type"::"Disk File" then begin
                RMSetup.TestField("Attachment Storage Location");
        end;
        case RMSetup."Attachment Storage Type" of
            RMSetup."Attachment Storage Type"::Embedded:
                begin
                    FileManagement.BLOBImportFromServerFile(TempBlob, ImportFromFile); // Copy from file on server (UNC location also)
                    SetAttachmentFileFromBlob(TempBlob);
                    "Storage Type" := "Storage Type"::Embedded;
                    "Storage Pointer" := '';
                    FileExt := CopyStr(FileManagement.GetExtension(ImportFromFile), 1, 250);
                    if FileExt <> '' then
                        "File Extension" := FileExt;
                    Modify(true);
                    exit(true);
                end;
            "Storage Type"::"Disk File":
                begin
                    "Storage Type" := "Storage Type"::"Disk File";
                    "Storage Pointer" := RMSetup."Attachment Storage Location";
                    //----------------------------------------------------OnImportAttachmentFromServerFileOnAfterValidateStoragePointer:BEGIN
                    OnImportAttachmentFromServerFileOnAfterValidateStoragePointer(Rec, RMSetup);
                    //----------------------------------------------------OnImportAttachmentFromServerFileOnAfterValidateStoragePointer:END
                    FileExt := CopyStr(FileManagement.GetExtension(ImportFromFile), 1, 250);
                    if FileExt <> '' then
                        "File Extension" := FileExt;
                    FileManagement.CopyServerFile(ImportFromFile, ConstDiskFileName(), Overwrite); // Copy from UNC location to another UNC location
                    Modify(true);
                    exit(true);
                end;
        end;

        exit(false);
    end;

    //----------------------------------------------------OnImportAttachmentFromServerFileOnAfterValidateStoragePointer:BEGIN
    [IntegrationEvent(false, false)]
    local procedure OnImportAttachmentFromServerFileOnAfterValidateStoragePointer(var Attachment: Record Attachment; var RMSetup: Record "Marketing Setup")
    begin
    end;
    //----------------------------------------------------OnImportAttachmentFromServerFileOnAfterValidateStoragePointer:END

Describe the request

Our function required different storage point that depends on "type" of table.
Internal work item: AB#592255

Metadata

Metadata

Assignees

No one assigned

    Labels

    IntegrationGitHub request for Integration areaevent-requestRequest for adding an event

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions