Adjustment of attachment file names after validation WIP
ÜberblickOverview
DieseThis Anleitungguide zeigt,shows wiehow Entwicklerdevelopers diecan Dateinamencustomize vonthe Anhängenfile names of attachments in DEXPRO SQUEEZESQUEEZE. anpassenThe können. Das Event OnBeforeAddLineToDocumentJObj wird event is executed nachafter derthe Plausibilitätsprüfungplausibility check ausgeführt,, sodassensuring allethat Belegdatenall vollständigdocument validiertdata undis verfügbarfully sind.validated and available.
VerfügbaresAvailable Event
OnBeforeAddLineToDocumentJObj
FürFor Rechnungen/Gutschriften:invoices/credit notes: Codeunit 70954657 "DXP SQZ P. Inv/Crdt Memo Impl."FürFor Bestellbestätigungen:orderconfirmations: Codeunit 70954658 "DXP SQZ P. Order Conf. Impl."
WannWhen aufgerufen:accessed: Nach Header-Verarbeitung,After vorheader Zeilen-Verarbeitung, processing, before line processing, nachafter Plausibilitätsprüfungplausibility check
ImplementierungsbeispieleImplementation examples
BeispielExample 1: EinfacherSimple Kreditorenprefixvendor fürprefix Rechnungen/Gutschriftenfor invoices/credit notes
codeunit 50100 "Custom Invoice Filename"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP SQZ P. Inv/Crdt Memo Impl.", 'OnBeforeAddLineToDocumentJObj', '', false, false)]
local procedure OnBeforeAddLineToDocumentJObjInvoice(var DocumentJObj: JsonObject; DocHeader: Record "DXP SQZ Document Header")
begin
CustomizeAttachmentFilenames(DocHeader);
end;
local procedure CustomizeAttachmentFilenames(DocHeader: Record "DXP SQZ Document Header")
var
DocumentAttachment: Record "DXP Document Attachment";
VendorPrefix: Text;
NewFileName: Text[1024];
begin
// Beenden, wenn keine Kreditorinformationen vorhanden
if DocHeader."Buy-from Vendor No." = '' then
exit;
// Kreditorenprefix erstellen
VendorPrefix := DocHeader."Buy-from Vendor No." + '_';
// Alle Anhänge für dieses Dokument bearbeiten
DocumentAttachment.Reset();
DocumentAttachment.SetRange("Document No.", DocHeader."Core Document No.");
if DocumentAttachment.FindSet(true) then
repeat
// Überspringen, wenn Prefix bereits vorhanden
if not DocumentAttachment."File Name".Contains(VendorPrefix) then begin
// Neuen Dateinamen mit Prefix erstellen
NewFileName := VendorPrefix + DocumentAttachment."File Name";
// Aktualisieren
DocumentAttachment."File Name" := CopyStr(NewFileName, 1, MaxStrLen(DocumentAttachment."File Name"));
DocumentAttachment.Modify(true);
end;
until DocumentAttachment.Next() = 0;
end;
}
BeispielExample 2: BestellbestätigungenOrder confirmations - Kreditorenprefixvendor prefix
codeunit 50101 "Custom Order Conf Filename"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP SQZ P. Order Conf. Impl.", 'OnBeforeAddLineToDocumentJObj', '', false, false)]
local procedure OnBeforeAddLineToDocumentJObjOrderConf(var DocumentJObj: JsonObject; DocHeader: Record "DXP SQZ Document Header")
begin
CustomizeAttachmentFilenames(DocHeader);
end;
local procedure CustomizeAttachmentFilenames(DocHeader: Record "DXP SQZ Document Header")
var
DocumentAttachment: Record "DXP Document Attachment";
VendorPrefix: Text;
NewFileName: Text[1024];
begin
// Beenden, wenn keine Kreditorinformationen vorhanden
if DocHeader."Buy-from Vendor No." = '' then
exit;
// Kreditorenprefix erstellen
VendorPrefix := DocHeader."Buy-from Vendor No." + '_';
// Alle Anhänge für dieses Dokument bearbeiten
DocumentAttachment.Reset();
DocumentAttachment.SetRange("Document No.", DocHeader."Core Document No.");
if DocumentAttachment.FindSet(true) then
repeat
// Überspringen, wenn Prefix bereits vorhanden
if not DocumentAttachment."File Name".Contains(VendorPrefix) then begin
// Neuen Dateinamen mit Prefix erstellen
NewFileName := VendorPrefix + DocumentAttachment."File Name";
// Aktualisieren
DocumentAttachment."File Name" := CopyStr(NewFileName, 1, MaxStrLen(DocumentAttachment."File Name"));
DocumentAttachment.Modify(true);
end;
until DocumentAttachment.Next() = 0;
end;
}
BeispielExample 3: BeideBoth Dokumenttypendocument types - VerschiedeneDifferent Prefixeprefixes fürfor Quelldateiensource files
codeunit 50102 "Advanced Filename Handling"
{
[EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP SQZ P. Inv/Crdt Memo Impl.", 'OnBeforeAddLineToDocumentJObj', '', false, false)]
local procedure OnBeforeAddLineToDocumentJObjInvoice(var DocumentJObj: JsonObject; DocHeader: Record "DXP SQZ Document Header")
begin
CustomizeFilenamesWithSourceHandling(DocHeader);
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"DXP SQZ P. Order Conf. Impl.", 'OnBeforeAddLineToDocumentJObj', '', false, false)]
local procedure OnBeforeAddLineToDocumentJObjOrderConf(var DocumentJObj: JsonObject; DocHeader: Record "DXP SQZ Document Header")
begin
CustomizeFilenamesWithSourceHandling(DocHeader);
end;
local procedure CustomizeAttachmentFilenames(DocHeader: Record "DXP SQZ Document Header")
var
DocumentAttachment: Record "DXP Document Attachment";
VendorPrefix: Text;
NewFileName: Text[1024];
begin
// Beenden, wenn keine Kreditorinformationen vorhanden
if DocHeader."Buy-from Vendor No." = '' then
exit;
// Kreditorenprefix erstellen
VendorPrefix := DocHeader."Buy-from Vendor No." + '_';
// Alle Anhänge für dieses Dokument bearbeiten
DocumentAttachment.Reset();
DocumentAttachment.SetRange("Document No.", DocHeader."Core Document No.");
if DocumentAttachment.FindSet(true) then
repeat
// Überspringen, wenn Prefix bereits vorhanden
if not DocumentAttachment."File Name".Contains(VendorPrefix) then begin
// Neuen Dateinamen mit Prefix erstellen
NewFileName := VendorPrefix + DocumentAttachment."File Name";
// Aktualisieren
DocumentAttachment."File Name" := CopyStr(NewFileName, 1, MaxStrLen(DocumentAttachment."File Name"));
DocumentAttachment.Modify(true);
end;
until DocumentAttachment.Next() = 0;
end;
}
PraktischePractical Hinweiseinformation
VerfügbareAvailable Datendata zurat Event-Zeit:the time of the event:
DocHeader."Buy-from Vendor No."- Kreditorennummer (validiert)DocHeader."Document Date"- BelegdatumDocHeader."Document Reference"- BelegnummerDocHeader."Core Document No."- Verknüpfung zu Anhängen- Alle anderen Belegfelder sind verfügbar
Beispielresultate:Example results:
- Original:
"Rechnung_2024_001.pdf" - Mit Kreditorenprefix:
"VEND001_Rechnung_2024_001.pdf" - Quelldatei:
"ORIGINAL_VEND001_Rechnung_2024_001.pdf"
Best Practices:
DuplikatprüfungDuplicate check:ImmerAlwaysprüfen,checkobwhetherPrefixprefixbereitsalreadyvorhandenexistsLängenvalidierungLength validation:NeueNewDateinamenfiledürfennamesmax.may have a maximum of 1024Zeichen habencharacters.