Skip to content

[Bug]: [W1][Codeunit][8900][Email Impl] Add OnBefore IntegrationEvent in FilterRemovedSourceRecords-procedure #8635

@dkastena

Description

@dkastena

Describe the issue

[W1][Codeunit][8900][Email Impl] Add OnBefore IntegrationEvent in FilterRemovedSourceRecords-procedure
Why do you need this change?
Hi,
If at least one security filter is applied to the “Purchase Header” table, the user will have a problem when pushing the 'Add file from source document’ action on the “Email Attachments” subpage. Message: "Did not find any attachments related to this email"

With this event, we will be able to add the following condition:
SourceRecordRef.SecurityFiltering(SecurityFilter::Ignored);
before reading permissions.

Expected behavior

Problem:
"Email Impl codeunit (ID 8900) lacks an integration event to allow extending/overriding the FilterRemovedSourceRecords logic"

Impact:
Partners cannot customize email behavior without forking the code or using workarounds

Solution:
Add OnBeforeIntegrationEvent in the FilterRemovedSourceRecords procedure

Steps to reproduce

  • Add at least one SecurityFilter to the "Purchase Header" table. For example:
    ‘Purchase Header: Vendor Posting Group=<>ALGEMEEN1’
Image
  • I opened the Purchase order document (“Vendor Posting Group” = ‘ALGEMEEN’), which has 3 attachments:
Image

I pushed the “Send by Email” action on the "Purchase Order" page:

Image

I pushed the ‘Add file from source document’ action on the “Email Attachments” subpage:

Image

Received a message: 'Did not find any attachments related to this email.'

Image

Expected result:
I expect to see the list of documents attached to my Purchase Order as it works without applied security filters to the "Purchase Header" table.

Additional context

Why we receive this message (technical explanation):

In the FilterRemovedSourceRecords function ("Email Impl" codeunit ID 8900), we have the following code:

Image

The system is trying to open the RecordRef variable for table 38 (line 702)

And for this opened RecordRef (without any applied filters), the system will check if we have ReadPermissions (line 703)

ReadPermissions return false because:
The documentation states:
https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/recordref/recordref-readpermission-method

This method uses the filter that is currently applied to the RecordRef to determine whether you have read permission. If no filter is applied, the method tests full read permission. If a filter has been set, the method only tests read permissions within the filter's range.

Microsoft code does SourceRecordRef.Open(38) with no filters applied. So ReadPermission() checks for full, unrestricted read permission on the entire table. Since our user has a security filter (Vendor Posting Group=<>ALGEMEEN1), he does not have full read permission — only partial. Hence, it returns false.

It doesn't matter that the current record (“Blanket Purchase Order”) has Vendor Posting Group = 'ALGEMEEN' — without a filter on the RecordRef, the check is against the whole table.

As a result, no attached documents were found because ReadPermission returned false for the Purchase Header record without any filters applied.

I will provide a fix for a bug

  • I will provide a fix for a bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    FinanceGitHub request for Finance area

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions