Media types are widely used in Business Central. This article shows practical tips for handling them. Learn how to view, import, transfer, and delete Media, and explore the differences between Media and MediaSet types.

  • How To See The Media Content Of Your Database
  • How To Import Item Pictures In Bulk
  • Differences Between Media And MediaSet Methods
  • How To Transfer Media
  • How To Delete Media
  • How To Use FindOrphans Method

In a previous article, we made an introduction to the Media and MediaSet data types. Where we explained how to import and export images using examples. For this post, we will be using these principles that you can find here.

How To See The Media Content Of Your Database


All the media is stored in the “Tenant Media” and “Tenant Media Set” tables.

In Media fields, there are only references to these tables via a generated GUID.

You can see Media records by accessing the “Table Information” page and drilling down to the records.

But in this table, you can’t preview the images.

However, you can create a simple page like the following to see them:

It’s as simple as creating two pages. A list and a factbox.

page 50005 "Tenant Media BCG"
{
    ApplicationArea = All;
    Caption = 'Tenant Media BCG';
    PageType = List;
    SourceTable = "Tenant Media";
    UsageCategory = Lists;

    layout
    {
        area(content)
        {
            repeater(General)
            {
                field(ID; Rec.ID)
                {
                    ToolTip = 'Specifies a unique identifier for this media.';
                }
                field(SystemModifiedAt; Rec.SystemModifiedAt)
                {
                    ToolTip = 'Specifies the value of the SystemModifiedAt field.';
                }
                field(Content1; Rec.Content)
                {
                    ToolTip = 'Specifies the picture of the media.';
                }
            }
        }

        area(FactBoxes)
        {
            part(Content2; "Tenant Media Factbox BCG")
            {
                SubPageLink = ID = field(ID);
            }
        }
    }
}
page 50006 "Tenant Media Factbox BCG"
{
    ApplicationArea = All;
    Caption = 'Tenant Media Factbox';
    PageType = CardPart;
    SourceTable = "Tenant Media";
    UsageCategory = None;

    layout
    {
        area(content)
        {
            field(Content1; Rec.Content)
            {
                ToolTip = 'Specifies the picture of the media.';
            }
        }
    }
}


How To Import Item Pictures In Bulk


In Business Central there is a standard feature where you can import item pictures in bulk. You just have to name your item pictures with the Item No. and compress them in a ZIP file.

For example, we will import these images for items “1000” and “1001”.


If you go to “Inventory Setup” you will find an action called “Import Item Pictures“.


A new page will open where you can import the ZIP file. You can see a preview of what you are going to import together with information about the pictures to add, replace, etc.

Once imported you can see the results:

In case you need it, you can replicate this tool to be used for other tables like customers, vendors, custom ones, etc.

Find more information in Microsoft’s documentation.

https://learn.microsoft.com/en-us/dynamics365/business-central/inventory-how-import-item-pictures

Differences Between Media and MediaSet Methods


Here are all the methods you can use for Media types. As you can see, there are some differences.

Be aware that ImportFile and ExportFile methods have scope “OnPrem“.

Find all detailed info for media methods here:

Media Data Type – Business Central | Microsoft Learn

And MediaSet methods:

MediaSet Data Type – Business Central | Microsoft Learn

How To Transfer Media


If you want to copy or transfer any media from one record to another it can be as simple as assigning it.

In this case, we reference to the same Media in the database. So they share the same GUID.

Using RecRef you can do something similar to this to transfer from one record to another.


If we set the “ExtendedDataType” property of a Media field to “Person” like this.


The result is that the images will be rounded.


How To Delete Media


For Media types we simply use “Clear” to delete. But be aware that the record in “Tenant Media” table gets deleted as well. So any media in other tables pointing to that record will be cleared.

For MediaSet types, there is a specific method called “Remove“. As Microsft says:

“The Remove method disassociates the media object from the MediaSet. It does not delete the media object from the database.”

You can use it like this:

Find more information here.

https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/mediaset/mediaset-remove-method

How To Use FindOrphans Method


To help in cleaning and saving storage, Microsoft introduced in BC23 the method “FindOrphans()” for Media and MediaSet. It will create a list of GUIDs for media that is not referenced in other tables in the database.


For example, if you delete an item with a picture, the picture will remain in the Tenant Media table.

This way, you can delete them and save some storage in your database.

Find more information here.

MediaSet.FindOrphans() Method – Business Central | Microsoft Learn


That´s all. Hope you find it helpful.

How To Handle Media Types Like A Pro In Business Central

Post navigation


3 thoughts on “How To Handle Media Types Like A Pro In Business Central

  1. Thanks very helpful. Would be really helpful to explore options for pulling images from a DAM or cheaper storage as well as 1000s of images really eats up storage space.

  2. Thank you for providing this info!
    Do you have any idea why Microsoft doesn’t delete them with FindOrphans() as part of a Retention Policy job?

Leave a Reply

Your email address will not be published. Required fields are marked *