Dynamics 365 Business Central: Remove Orphaned Record Links

Dynamics 365 Business Central

Hi, Readers.
Today I would like to share another mini tip about Business Central, how to remove orphaned Record Links.
As you might know, there are two system parts that you can define by using the systempart() keyword: Links and Notes: System Parts

ValueDescription
LinksAllows the user to add links to a URL or path on the record shown in the page. For example, on an Item card, a user can add a link to the supplier’s item catalog. The links will appear with the record when it is viewed. When a user chooses a link, the target file opens.
NotesAllows the user to write a note on the record shown in the page. For example, when creating a sales order, a user can add a note about the order. The note will appear with the item when it is viewed.

We’ve discussed how to import, export, and copy Links and Notes before. More details:

If you delete the record normally from the BC page, the related links will also be automatically removed. But there are some special cases, for example, if this is an upgrade project from NAV or if redundant or incorrectly recorded Links have been imported from code directly, is there an easy way to clear them? Of course, we can manually search in table 2000000068 “Record Link” and then clear it. But Microsoft has prepared a standard method for us. Let’s see more details.

1. codeunit 459 “Remove Orphaned Record Links”

CodeUnit Remove Orphaned Record Links: This codeunit is created so that record links that have obsolete record ids can be deleted in a scheduled task.

2. codeunit 447 “Record Link Management” -> procedure RemoveOrphanedLinks()

CodeUnit Record Link Management: Exposes functionality to administer record links related to table records.

RemoveOrphanedLinks: Iterates over the record link table and removes those with obsolete record ids.

The following method is used in both codeunits. The difference is that codeunit 459 “Remove Orphaned Record Links” can be set directly in the Job Queue to do regular cleaning when needed.
codeunit 4470 “Record Link Impl.” (Access = Internal):

Let’s see a specific example.

Source code:

pageextension 50101 ZYItemListExt extends "Item List"
{
    actions
    {
        addfirst(processing)
        {
            action("Remove Orphaned Record Links")
            {
                Caption = 'Remove Orphaned Record Links';
                ApplicationArea = All;
                Promoted = true;
                PromotedCategory = Process;
                PromotedIsBig = true;
                Image = RemoveLine;
                trigger OnAction()
                var
                    RemoveOrphanedRecordLinks: Codeunit "Remove Orphaned Record Links";
                begin
                    RemoveOrphanedRecordLinks.Run();
                end;
            }
        }
    }
}

Do you want to remove links with no record reference?

6 orphaned links were removed.

Very simple, give it a try!!!😁

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL