From 26642e526b31f1a55a85c964477271e39b4d9c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Hartvig=20Gr=C3=B8nbech?= Date: Wed, 24 Jun 2026 13:22:53 +0200 Subject: [PATCH] Add OnBeforeFilterRemovedSourceRecords integration event in Email Impl (#8635) Adds an OnBefore integration event to the FilterRemovedSourceRecords procedure in codeunit 8900 "Email Impl", published via codeunit 8901 Email. This lets partners override the default filtering (which relies on RecordRef.ReadPermission against an unfiltered RecordRef) so they can, for example, apply SecurityFiltering::Ignored before the permission check. Without this, users with a security filter on a source table get 'Did not find any attachments related to this email' when adding files from the source document. Fixes #8635 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../App/Email/src/Email/Email.Codeunit.al | 10 ++++++++++ .../App/Email/src/Email/EmailImpl.Codeunit.al | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/src/System Application/App/Email/src/Email/Email.Codeunit.al b/src/System Application/App/Email/src/Email/Email.Codeunit.al index 1e8b55a9db..7d5b095411 100644 --- a/src/System Application/App/Email/src/Email/Email.Codeunit.al +++ b/src/System Application/App/Email/src/Email/Email.Codeunit.al @@ -651,6 +651,16 @@ codeunit 8901 Email begin end; + /// + /// Integration event that allows overriding the filtering of related source records before they are shown. + /// + /// The related source records to filter. Subscribers can apply their own filtering, for example to ignore security filtering when determining read permission. + /// Out parameter to set if the event was handled. If set to true, the default filtering is skipped. + [IntegrationEvent(false, false)] + internal procedure OnBeforeFilterRemovedSourceRecords(var EmailRelatedRecord: Record "Email Related Record"; var IsHandled: Boolean) + begin + end; + /// /// Integration event to add additional relations based on added relation to emails. /// diff --git a/src/System Application/App/Email/src/Email/EmailImpl.Codeunit.al b/src/System Application/App/Email/src/Email/EmailImpl.Codeunit.al index e275ad0ac1..23ebcab7b1 100644 --- a/src/System Application/App/Email/src/Email/EmailImpl.Codeunit.al +++ b/src/System Application/App/Email/src/Email/EmailImpl.Codeunit.al @@ -745,8 +745,14 @@ codeunit 8900 "Email Impl" procedure FilterRemovedSourceRecords(var EmailRelatedRecord: Record "Email Related Record") var AllObj: Record AllObj; + Email: Codeunit Email; SourceRecordRef: RecordRef; + IsHandled: Boolean; begin + Email.OnBeforeFilterRemovedSourceRecords(EmailRelatedRecord, IsHandled); + if IsHandled then + exit; + repeat if AllObj.Get(AllObj."Object Type"::Table, EmailRelatedRecord."Table Id") then begin SourceRecordRef.Open(EmailRelatedRecord."Table Id");