Anpassung der Dateinamen von Anhängen nach der Validierung
Anpassung der Dateinamen von Anhängen nach der Validierung
Überblick
Diese Anleitung zeigt, wie Entwickler die Dateinamen von Anhängen in DEXPRO SQUEEZE anpassen können. Das Event OnBeforeAddLineToDocumentJObj wird nach der Plausibilitätsprüfung ausgeführt, sodass alle Dokumentdaten (Kopf) vollständig validiert und verfügbar sind.
Verfügbares Event
OnBeforeAddLineToDocumentJObj
Für Rechnungen/Gutschriften: Codeunit 70954657 "DXP SQZ P. Inv/Crdt Memo Impl."
Für Bestellbestätigungen: Codeunit 70954658 "DXP SQZ P. Order Conf. Impl."
Wann aufgerufen: Nach Header-Verarbeitung, vor Zeilen-Verarbeitung, nach Plausibilitätsprüfung
Implementierungsbeispiele
Beispiel 1: Einfacher Kreditorenprefix für Rechnungen/Gutschriften
xxxxxxxxxx1
codeunit 50100 "Custom Invoice Filename"2
{3
[EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP SQZ P. Inv/Crdt Memo Impl.", 'OnBeforeAddLineToDocumentJObj', '', false, false)]4
local procedure OnBeforeAddLineToDocumentJObjInvoice(var DocumentJObj: JsonObject; DocHeader: Record "DXP SQZ Document Header")5
begin6
CustomizeAttachmentFilenames(DocHeader);7
end;8
9
local procedure CustomizeAttachmentFilenames(DocHeader: Record "DXP SQZ Document Header")10
var11
DocumentAttachment: Record "DXP Document Attachment";12
VendorPrefix: Text;13
NewFileName: Text[1024];14
begin15
// Beenden, wenn keine Kreditorinformationen vorhanden16
if DocHeader."Buy-from Vendor No." = '' then17
exit;18
19
// Kreditorenprefix erstellen20
VendorPrefix := DocHeader."Buy-from Vendor No." + '_';21
22
// Alle Anhänge für dieses Dokument bearbeiten23
DocumentAttachment.Reset();24
DocumentAttachment.SetRange("Document No.", DocHeader."Core Document No.");25
26
if DocumentAttachment.FindSet(true) then27
repeat28
// Überspringen, wenn Prefix bereits vorhanden29
if StrPos(DocumentAttachment."File Name", VendorPrefix) <> 1 then begin30
// Neuen Dateinamen mit Prefix erstellen31
NewFileName := VendorPrefix + DocumentAttachment."File Name";32
33
// Aktualisieren, wenn es passt34
if StrLen(NewFileName) <= MaxStrLen(DocumentAttachment."File Name") then begin35
DocumentAttachment."File Name" := CopyStr(NewFileName, 1, MaxStrLen(DocumentAttachment."File Name"));36
DocumentAttachment.Modify(true);37
end;38
end;39
until DocumentAttachment.Next() = 0;40
end;41
}42
Beispiel 2: Bestellbestätigungen - Kreditorenprefix
xxxxxxxxxx1
codeunit 50101 "Custom Order Conf Filename"2
{3
[EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP SQZ P. Order Conf. Impl.", 'OnBeforeAddLineToDocumentJObj', '', false, false)]4
local procedure OnBeforeAddLineToDocumentJObjOrderConf(var DocumentJObj: JsonObject; DocHeader: Record "DXP SQZ Document Header")5
begin6
CustomizeAttachmentFilenames(DocHeader);7
end;8
9
local procedure CustomizeAttachmentFilenames(DocHeader: Record "DXP SQZ Document Header")10
var11
DocumentAttachment: Record "DXP Document Attachment";12
VendorPrefix: Text;13
NewFileName: Text[1024];14
begin15
// Beenden, wenn keine Kreditorinformationen vorhanden16
if DocHeader."Buy-from Vendor No." = '' then17
exit;18
19
// Kreditorenprefix erstellen20
VendorPrefix := DocHeader."Buy-from Vendor No." + '_';21
22
// Alle Anhänge für dieses Dokument bearbeiten23
DocumentAttachment.Reset();24
DocumentAttachment.SetRange("Document No.", DocHeader."Core Document No.");25
26
if DocumentAttachment.FindSet(true) then27
repeat28
// Überspringen, wenn Prefix bereits vorhanden29
if StrPos(DocumentAttachment."File Name", VendorPrefix) <> 1 then begin30
// Neuen Dateinamen mit Prefix erstellen31
NewFileName := VendorPrefix + DocumentAttachment."File Name";32
33
// Aktualisieren, wenn es passt34
if StrLen(NewFileName) <= MaxStrLen(DocumentAttachment."File Name") then begin35
DocumentAttachment."File Name" := CopyStr(NewFileName, 1, MaxStrLen(DocumentAttachment."File Name"));36
DocumentAttachment.Modify(true);37
end;38
end;39
until DocumentAttachment.Next() = 0;40
end;41
}42
Beispiel 3: Beide Dokumenttypen - Verschiedene Prefixe für Quelldateien
xxxxxxxxxx1
codeunit 50102 "Advanced Filename Handling"2
{3
[EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP SQZ P. Inv/Crdt Memo Impl.", 'OnBeforeAddLineToDocumentJObj', '', false, false)]4
local procedure OnBeforeAddLineToDocumentJObjInvoice(var DocumentJObj: JsonObject; DocHeader: Record "DXP SQZ Document Header")5
begin6
CustomizeFilenamesWithSourceHandling(DocHeader);7
end;8
9
[EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP SQZ P. Order Conf. Impl.", 'OnBeforeAddLineToDocumentJObj', '', false, false)]10
local procedure OnBeforeAddLineToDocumentJObjOrderConf(var DocumentJObj: JsonObject; DocHeader: Record "DXP SQZ Document Header")11
begin12
CustomizeFilenamesWithSourceHandling(DocHeader);13
end;14
15
local procedure CustomizeFilenamesWithSourceHandling(DocHeader: Record "DXP SQZ Document Header")16
var17
DocumentAttachment: Record "DXP Document Attachment";18
VendorPrefix: Text;19
SourcePrefix: Text;20
NewFileName: Text[1024];21
PrefixToUse: Text;22
begin23
// Beenden, wenn keine Kreditorinformationen vorhanden24
if DocHeader."Buy-from Vendor No." = '' then25
exit;26
27
// Prefixe erstellen28
VendorPrefix := DocHeader."Buy-from Vendor No." + '_';29
SourcePrefix := 'ORIGINAL_' + DocHeader."Buy-from Vendor No." + '_';30
31
// Alle Anhänge bearbeiten32
DocumentAttachment.Reset();33
DocumentAttachment.SetRange("Document No.", DocHeader."Core Document No.");34
35
if DocumentAttachment.FindSet(true) then36
repeat37
// Prefix je nach Dateityp wählen38
if DocumentAttachment."Is Source File" then39
PrefixToUse := SourcePrefix40
else41
PrefixToUse := VendorPrefix;42
43
// Überspringen, wenn Prefix bereits vorhanden44
if StrPos(DocumentAttachment."File Name", PrefixToUse) <> 1 then begin45
NewFileName := PrefixToUse + DocumentAttachment."File Name";46
47
if StrLen(NewFileName) <= MaxStrLen(DocumentAttachment."File Name") then begin48
DocumentAttachment."File Name" := CopyStr(NewFileName, 1, MaxStrLen(DocumentAttachment."File Name"));49
DocumentAttachment.Modify(true);50
end;51
end;52
until DocumentAttachment.Next() = 0;53
end;54
}55
Verfügbare Daten zur Event-Zeit:
DocHeader."Buy-from Vendor No."- Kreditorennummer (validiert)DocHeader."Document Date"- DokumentdatumDocHeader."Document Reference"- DokumentreferenzDocHeader."Core Document No."- Verknüpfung zu Anhängen- Alle anderen Dokumentfelder sind verfügbar
Beispielresultate:
- Original:
"Rechnung_2024_001.pdf" - Mit Kreditorenprefix:
"VEND001_Rechnung_2024_001.pdf" - Quelldatei:
"ORIGINAL_VEND001_Rechnung_2024_001.pdf"
Best Practices:
- Duplikatprüfung: Immer prüfen, ob Prefix bereits vorhanden
- Längenvalidierung: Neue Dateinamen dürfen max. 1024 Zeichen habe