[Event Request] codeunit 1173 "Document Attachment Mgmt" Has methods and extendibility suggestions
It's too complicated to add attachments to new tables; please add publishers to the following procedures
[IntegrationEvent(false, false)]
local procedure OnAfterTableHasNumberFieldPrimaryKey(TableNo: Integer; var ReturnValue: Boolean, var FieldNo: Integer)
begin
end
[IntegrationEvent(false, false)]
local procedure OnAfterTableHasDocTypePrimaryKey(TableNo: Integer; var ReturnValue: Boolean, var FieldNo: Integer)
begin
end
[IntegrationEvent(false, false)]
local procedure OnAfterTableHasLineNumberPrimaryKey(TableNo: Integer; var ReturnValue: Boolean, var FieldNo: Integer)
begin
end
internal procedure TableHasNumberFieldPrimayKey(TableNo: Integer; var FieldNo: Integer): Boolean
var
ReturnValue: Boolean;
begin
if TableNo in
[DATABASE::Customer,
DATABASE::Vendor,
DATABASE::Item,
DATABASE::Employee,
DATABASE::"Fixed Asset",
DATABASE::Job,
DATABASE::Resource,
DATABASE::"VAT Report Header"]
then begin
FieldNo := 1;
exit(true);
end;
if TableNo in
[DATABASE::"Sales Header",
DATABASE::"Sales Line",
DATABASE::"Purchase Header",
DATABASE::"Purchase Line",
DATABASE::"Sales Invoice Header",
DATABASE::"Sales Cr.Memo Header",
DATABASE::"Purch. Inv. Header",
DATABASE::"Purch. Cr. Memo Hdr.",
DATABASE::"Sales Invoice Line",
DATABASE::"Sales Cr.Memo Line",
DATABASE::"Purch. Inv. Line",
DATABASE::"Purch. Cr. Memo Line"]
then begin
FieldNo := 3;
exit(true);
end;
OnAfterTableHasNumberFieldPrimaryKey(TableNo, ReturnValue, FieldNo);
exit(ReturnValue);
end;
internal procedure TableHasDocTypePrimaryKey(TableNo: Integer; var FieldNo: Integer): Boolean
var
ReturnValue: Boolean;
begin
if TableNo in
[DATABASE::"Sales Header",
DATABASE::"Sales Line",
DATABASE::"Purchase Header",
DATABASE::"Purchase Line"]
then begin
FieldNo := 1;
exit(true);
end;
OnAfterTableHasDocTypePrimaryKey(TableNo, ReturnValue, FieldNo);
exit(ReturnValue);
end;
internal procedure TableHasLineNumberPrimaryKey(TableNo: Integer; var FieldNo: Integer): Boolean
var
ReturnValue: Boolean;
begin
if TableNo in
[DATABASE::"Sales Line",
DATABASE::"Purchase Line",
DATABASE::"Sales Invoice Line",
DATABASE::"Sales Cr.Memo Line",
DATABASE::"Purch. Inv. Line",
DATABASE::"Purch. Cr. Memo Line"]
then begin
FieldNo := 4;
exit(true);
end;
OnAfterTableHasLineNumberPrimaryKey(TableNo, ReturnValue, FieldNo);
exit(ReturnValue);
end;
Also, I would suggest to do a change on the page 1173 "Document Attachment Details" and replace SetDocumentAttachmentFiltersForRecRefInternal in the following procedure with SetDocumentAttachmentFiltersForRecRef. The only difference is that the SetDocumentAttachmentFiltersForRecRef procedure contains a publisher. There is also a super easy workaround (see code below) by calling SetDocumentAttachmentFiltersForRecRef in the OnAfterOpenForRecRef, so again no reason to hide it. It just forces partners to make the code nonoptimal
procedure OpenForRecRef(RecRef: RecordRef)
var
DocumentAttachmentMgmt: Codeunit "Document Attachment Mgmt";
begin
Rec.Reset();
FromRecRef := RecRef;
SalesDocumentFlow := DocumentAttachmentMgmt.IsSalesDocumentFlow(RecRef.Number);
PurchaseDocumentFlow := DocumentAttachmentMgmt.IsPurchaseDocumentFlow(RecRef.Number);
FlowFieldsEditable := DocumentAttachmentMgmt.IsFlowFieldsEditable(RecRef.Number);
DocumentAttachmentMgmt.SetDocumentAttachmentFiltersForRecRefInternal(Rec, RecRef);
OnAfterOpenForRecRef(Rec, RecRef, FlowFieldsEditable);
end;
procedure SetDocumentAttachmentFiltersForRecRef(var DocumentAttachment: Record "Document Attachment"; RecRef: RecordRef)
begin
SetDocumentAttachmentFiltersForRecRefInternal(DocumentAttachment, RecRef);
OnAfterSetDocumentAttachmentFiltersForRecRef(DocumentAttachment, RecRef);
end;
Right now, the workaround is (see below), so there is no reason not allow to specify a custom table.
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Document Attachment Mgmt", 'OnAfterSetDocumentAttachmentFiltersForRecRef', '', false, false)]
local procedure OnAfterSetDocumentAttachmentFiltersForRecRefDocumentAttachmentMgmt(RecRef: RecordRef; var DocumentAttachment: Record "Document Attachment")
var
ManfChangeOrder: Record "TKA Manf. Change Order";
FieldRef: FieldRef;
begin
case RecRef.Number() of
Database::"TKA Manf. Change Order":
begin
FieldRef := RecRef.Field(ManfChangeOrder.FieldNo("Item No."));
DocumentAttachment.SetRange("No.", FieldRef.Value());
FieldRef := RecRef.Field(ManfChangeOrder.FieldNo("Line No."));
DocumentAttachment.SetRange("Line No.", FieldRef.Value());
end;
end;
end;
[EventSubscriber(ObjectType::Table, Database::"Document Attachment", 'OnAfterInitFieldsFromRecRef', '', false, false)]
local procedure OnAfterInitFieldsFromRecRefDocumentAttachment(var RecRef: RecordRef; var DocumentAttachment: Record "Document Attachment")
var
ManfChangeOrder: Record "TKA Manf. Change Order";
FieldRef: FieldRef;
begin
case RecRef.Number() of
Database::"TKA Manf. Change Order":
begin
FieldRef := RecRef.Field(ManfChangeOrder.FieldNo("Item No."));
DocumentAttachment.Validate("No.", FieldRef.Value());
FieldRef := RecRef.Field(ManfChangeOrder.FieldNo("Line No."));
DocumentAttachment.Validate("Line No.", FieldRef.Value());
end;
end;
end;
[EventSubscriber(ObjectType::Page, Page::"Document Attachment Details", 'OnAfterOpenForRecRef', '', false, false)]
local procedure OnAfterOpenForRecRefDocumentAttachmentDetails(var DocumentAttachment: Record "Document Attachment"; var RecRef: RecordRef)
var
DocumentAttachmentMgmt: Codeunit "Document Attachment Mgmt";
begin
DocumentAttachmentMgmt.SetDocumentAttachmentFiltersForRecRef(DocumentAttachment, RecRef);
end;
Hello,
Thank you on your suggestion. Please, for second part, create new, access request. With current GitHub request, we will cover only part for adding new events under the Document Attachment Mgmt
Thanks for reporting this. We agree, and we’ll publish a fix asap, either in an update for the current version or in the next major release. Please do not reply to this, as we do not monitor closed issues. If you have follow-up questions or requests, please create a new issue where you reference this one.
Build ID: 10902.