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’
- I opened the Purchase order document (“Vendor Posting Group” = ‘ALGEMEEN’), which has 3 attachments:
I pushed the “Send by Email” action on the "Purchase Order" page:
I pushed the ‘Add file from source document’ action on the “Email Attachments” subpage:
Received a message: 'Did not find any attachments related to this email.'
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:
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
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
‘Purchase Header: Vendor Posting Group=<>ALGEMEEN1’
I pushed the “Send by Email” action on the "Purchase Order" page:
I pushed the ‘Add file from source document’ action on the “Email Attachments” subpage:
Received a message: 'Did not find any attachments related to this email.'
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:
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