ECM Smart Connect - EDS
EDS - Electronic Document Storage
Loads and stores a document from an input stream into the system, with support for metadata classification, versioning, and optional processing. This method is overloaded to support various use cases.
Syntax
StorageManagement.ImportDocument(InStr, RecID, FileExtension [, DocType] [, StorageEntryNo] [, Versioning] [, BaseVersionStorageEntry] [, IncomingDocType] [, RunProcessing])
Parameters
Name | Type | Description |
---|---|---|
InStr |
InStream | The stream containing the document to import. |
RecID |
RecordId | Identifies the target record to associate the imported document with. |
FileExtension |
Text | The file extension of the imported document (e.g., pdf , xml ). |
DocType |
Text[50] | (Optional) Specifies which Document Type should be used for this document. If omitted, a Document Type will automatically be selected. |
StorageEntryNo |
Code[20] | (Optional)(VAR) Returns the document's internal storage entry number. |
Versioning |
Boolean | (Optional) Specifies whether the import should consider document versioning. |
BaseVersionStorageEntry |
Code[20] | (Optional) Storage entry number of the base document version to link to. |
IncomingDocType |
Enum "kmiecmIncoming Doc. Type" | (Optional) A predefined enum indicating the type of incoming document. Default: pdf |
RunProcessing |
Boolean | (Optional) Indicates whether the document should be directly transferred to the archive. |
Return Value
Code[20] (via StorageEntryNo
)
If the StorageEntryNo
parameter is passed by reference, it returns the entry number of the stored document.
Remarks
Use this method to import documents into the system with flexible support for optional classification, version tracking, and custom logic execution. Depending on the overload used, you can control how the document is stored and processed.
Examples
Example 1: Only required parameters
In this example, only the required parameters are used (InStr
, RecID
, FileExtension
).
trigger OnAction()
var
SalesHeader: Record "Sales Header";
SalesOrderRep: Report "Standard Sales - Order Conf.";
StorageManagement: Codeunit "kmiecmStorage Management";
TempBlob: Codeunit "Temp Blob";
InStr: InStream;
OutStr: OutStream;
begin
SalesHeader := Rec;
SalesHeader.SetRecFilter();
SalesOrderRep.SetTableView(SalesHeader);
TempBlob.CreateOutStream(OutStr);
if SalesOrderRep.SaveAs('<ReportParameter>', ReportFormat::Pdf, OutStr) then begin
TempBlob.CreateInStream(InStr);
StorageManagement.ImportDocument(InStr, SalesHeader.RecordId, '.pdf');
end;
end;
Example 2: All optional parameters
In this example, all optional parameters are used (DocType
, StorageEntryNo
, Versioning
, BaseVersionStorageEntry
, IncomingDocType
, RunProcessing
).
trigger OnAction()
var
DocType: Record "kmiecmDocument Type";
SalesHeader: Record "Sales Header";
SalesOrderRep: Report "Standard Sales - Order Conf.";
StorageManagement: Codeunit "kmiecmStorage Management";
TempBlob: Codeunit "Temp Blob";
InStr: InStream;
OutStr: OutStream;
RunProcessing: Boolean;
Versioning: Boolean;
BaseVersionStorageEntry: Code[20];
StorageEntryNo: Code[20];
IncomingDocType: Enum "kmiecmIncoming Doc. Type";
begin
SalesHeader := Rec;
SalesHeader.SetRecFilter();
GetDocType(DocType, SalesHeader);
GetVersioning(SalesHeader, Versioning, BaseVersionStorageEntry);
IncomingDocType := Enum::"kmiecmIncoming Doc. Type"::EDA;
RunProcessing := true;
SalesOrderRep.SetTableView(SalesHeader);
TempBlob.CreateOutStream(OutStr);
if SalesOrderRep.SaveAs('', ReportFormat::Pdf, OutStr) then begin
TempBlob.CreateInStream(InStr);
if Versioning then
StorageManagement.ImportDocument(InStr, SalesHeader.RecordId, '.pdf', DocType."No.", StorageEntryNo, Versioning, BaseVersionStorageEntry, IncomingDocType, RunProcessing, Report::"Standard Sales - Order Conf.")
else
StorageManagement.ImportDocument(InStr, SalesHeader.RecordId, '.pdf', DocType."No.", StorageEntryNo, IncomingDocType, RunProcessing, Report::"Standard Sales - Order Conf.");
if StorageEntryNo = '' then
Error('No storage entry was created for this record.');
end;
end;
local procedure GetDocType(var DocType: Record "kmiecmDocument Type"; SalesHeader: Record "Sales Header")
var
FpEntry: Record "kmiecmFileplan Entry";
FPEntrySubscriber: Codeunit "kmiecmFPEntry Subscriber";
RecRef: RecordRef;
MissingFileplanEntryErr: Label 'No fileplan entry found for this record.';
MissingDocTypeErr: Label 'No document type found for this record.';
begin
RecRef.Open(Database::"Sales Header");
RecRef.Get(SalesHeader.RecordId);
FPEntrySubscriber.InsertOrModifyFpEntryGlobal(RecRef, true);
FpEntry.SetRange("Record ID", SalesHeader.RecordId());
FpEntry.SetLoadFields("Fileplan No.");
if not FpEntry.FindFirst() then
Error(MissingFileplanEntryErr);
DocType.SetRange("Fileplan Element No.", FpEntry."Fileplan No.");
DocType.SetRange(Direction, DocType.Direction::Incoming);
if not DocType.FindFirst() then
Error(MissingDocTypeErr);
end;
local procedure GetVersioning(SalesHeader: Record "Sales Header"; var Versioning: Boolean; var BaseVersionStorageEntry: Code[20])
var
FpEntry: Record "kmiecmFileplan Entry";
StorageEntry: Record "kmiecmStorage Entry";
begin
BaseVersionStorageEntry := '';
FpEntry.SetRange("Record ID", SalesHeader.RecordId());
FpEntry.SetLoadFields("No.");
if FpEntry.FindFirst() then begin
StorageEntry.SetRange("FP Entry No.", FpEntry."No.");
if StorageEntry.FindFirst() then
BaseVersionStorageEntry := StorageEntry."No.";
end;
Versioning := BaseVersionStorageEntry <> '';
end;
EDS - Update Orders
A global function is available for use to trigger update orders. This requires the following parameters:
- RecRelatedVariant (Variant)
- The source record from which one or more values are to be transferred
- TargetRecID (RecordId)
- The record ID of the target record. This must still exist
In order for a setup of update order to be used via the EDS, "Allow update with EDS" must be activated in the setup
EDS - example
trigger OnAction()
var
PurchaseOrder: "Purchase Header" record;
UpdMgt: Codeunit "kmiecmUpdate Management";
begin
if PurchaseOrder.Get(PurchaseOrder. "Document Type"::Order, Rec. "Order No.") then
UpdMgt.InsertUpdateOrderEDA(Rec, PurchaseOrder.RecordId);
end;