Hi, Readers.
Today I would like to talk about how to delete detached/orphaned media (that is not being actively referenced) on the page.
As you might know, there are two ways that you can upload media in Business Central:
- Use a BLOB data type: You add media to a BLOB data type field on the record. For more information, see BLOB Data Type.
For example, Picture in Company Information
- Use a Media or MediaSet data type: This way enables you to store media in system tables of the database, and then reference the media from application records. For example, you can:
- Display media with records in list type pages, when the page is viewed in the Tile layout. For more information, see Displaying Data as Tiles.
- Display media on a card type page for a record.
- Display media in a report.
Attachments:
Customer Picture:
Using the Media or MediaSet data type provides better performance than using a BLOB data type and is more flexible in its design. With a BLOB data type, each time the media is rendered in the client, it’s retrieved from the SQL database server, which requires extra bandwidth and affects performance. With the Media and MediaSet data types, the client uses media ID to cache the media data, which in turn improves the response time for rendering the media in the user interface. More details: Working With Media on Records
Table fields support two data types for adding media to records: Media and MediaSet. With these data types, you can import media directly from a file to a record, or media can be passed to the record in an InStream object.
Imported media is stored as an object in the system table 2000000184 Tenant Media of the tenant database. Each media object is assigned a unique identifier (ID).
If a media object is added to MediaSet data type field, the media object is assigned to a media set in the system table 2000000183 Tenant Media Set. The media set is assigned a unique identifier, which is then referenced from the field. The media set is created with the first file media object that you add on the record. Any other media objects for the record are then associated with the same media set.
By default, Business Central customers can use up to 80 GB plus an allowance per licensed Essentials or Premium user of database storage capacity. Table and database sizes have a significant impact on the performance of Business Central online. Therefore, it is very important to manage the capacity in tenant. More details: Dynamics 365 Business Central: How to check tenant size, environment size, company size and table size (Database storage)
Since media files occupy the largest space, how to clean up unused media files has always been a problem. In Business Central 2023 wave 1 (BC22), Microsoft released the Media.FindOrphans() Method and MediaSet.FindOrphans() Method. We can use these two methods to discover all orphaned media and media sets, then delete them from the code.
Actually in recent versions, users can do this from the BC page. Let’s see more details.
Choose the Tell Me icon, enter Data Administration, and then choose the related link.
Choose Actions -> Data Cleanup -> Miscellaneous -> Delete Detached media…
Delete Detached media: Delete media that is not being actively referenced.
Then there is a new page here, Detached Media Cleanup page
This page provides an overview of what kinds of detached media you have. Detached media is media which is not directly referenced. All Microsoft extensions references media directly. You can either delete individual detached media or schedule a background task to clear all detached media when you are ready.
Load Limit: Specifies the maximum number of records to load. Depending on the limit, this may take a long time to complete.
Company Filter: Specifies the filter to a specific company.
Load Detached Media Set: Specifies whether media from detached media sets should be included.
For example, choose Load Detached Media.
If there is detached media in the environment, the details will be displayed. Thumbnails will be displayed in the Media picture factbox. This depends on the type. Formats such as PDF cannot be viewed directly.
On this page, you can delete detached media or download media, or schedule a background task to clear all detached media.
PS: Please do not use Manage -> Delete to delete detached media, because the system table cannot be deleted directly and an insufficient permission error will be prompted.
Sorry, the current permissions prevented the action. (TableData 2000000184 Tenant Media Delete: System Application)
Test video:
Very simple, give it a try!!!😁
END
Hope this will help.
Thanks for reading.
ZHU
コメント