Hello, I am attaching doc. Via process, but it takes only one document and doesn't insert on new document attachment. What should I change in code for doing this properly., i.e attach one more document for same doc. No.
Procedure attachdoc(No: code[30]; name: text; Ext: text; Base64: Text)
var
DocAttach: Record "Document Attachment";
DocAttach2: Record "Document Attachment";
Base64cu: Codeunit "Base64 Convert";
OutStream: OutStream;
InStream: InStream;
ltext: Text;
tempblob: Codeunit "Temp Blob";
FileMgmnt: Codeunit "File Management";
SalesHdr: Record "Sales Header";
WhseLine: Record "Warehouse Shipment Line";
WhseHdr: Record "Warehouse Shipment Header";
lineno: Integer;
begin
WhseHdr.Reset();
WhseHdr.SetRange("No.", no);
if WhseHdr.Findfirst then begin
Whseline.Reset();
Whseline.setrange("No.", Whsehdr."No.");
if Whseline.FindFirst() then begin
SalesHdr.Reset();
SalesHdr.SetRange("No.", Whseline."Source No.");
SalesHdr.SetRange("Document Type", SalesHdr."Document Type"::"Order");
if SalesHdr.Findlast() then begin
DocAttach2.SetRange("Table ID", 36);
DocAttach2.SetRange("No.", SalesHdr."No.");
if DocAttach2.FindLast() then
lineno := DocAttach2."Line No." + 10000
Else
lineno := 10000;
DocAttach.Reset();
DocAttach.SetRange("Table ID", 36);
DocAttach.SetRange("No.", SalesHdr."No.");
if not DocAttach.FindFirst() then begin
DocAttach.Init();
DocAttach.ID := DocAttach.ID + 1;
DocAttach."Table ID" := 36;
DocAttach."Line No." := lineno;
DocAttach."No." := SalesHdr."No.";
DocAttach."Document Type" := SalesHdr."Document Type";
DocAttach."Attached By" := UserSecurityId();
DocAttach.User := UserId;
DocAttach."Attached Date" := CurrentDateTime;
if (ext = 'jpg') then
DocAttach."File Extension" := ext;
DocAttach."File Type" := DocAttach."File Type"::Image;
DocAttach."File Name" := FileMgmnt.GetFileNameWithoutExtension(name);
TempBlob.CreateOutStream(OutStream);
Base64cu.FromBase64(Base64, outStream);
TempBlob.CreateInStream(InStream);
CopyStream(OutStream, InStream);
DocAttach."Document Reference ID".ImportStream(InStream, '');
DocAttach.Insert();
end;
end;
end;
end;
end;