diff --git a/src/System Application/App/Data Administration/src/MediaCleanupImpl.Codeunit.al b/src/System Application/App/Data Administration/src/MediaCleanupImpl.Codeunit.al index 92926aaabf..45cf4ed151 100644 --- a/src/System Application/App/Data Administration/src/MediaCleanupImpl.Codeunit.al +++ b/src/System Application/App/Data Administration/src/MediaCleanupImpl.Codeunit.al @@ -165,6 +165,7 @@ codeunit 1928 "Media Cleanup Impl." SplitList: List of [List of [Guid]]; MediaSetOrphans: List of [Guid]; MediaOrphanSubList: List of [Guid]; + TenantMediaFilter: Text; begin if not TenantMediaSet.WritePermission() then exit; @@ -172,9 +173,12 @@ codeunit 1928 "Media Cleanup Impl." MediaSetOrphans := MediaSet.FindOrphans(); SplitListIntoSubLists(MediaSetOrphans, 10, SplitList); foreach MediaOrphanSubList in SplitList do begin - TenantMediaSet.SetFilter(ID, CreateOrFilter(MediaOrphanSubList)); - TenantMediaSet.DeleteAll(); - Commit(); // Ensure we keep the progress even on timeout (in case of large amounts of detached media). + TenantMediaFilter := CreateOrFilter(MediaOrphanSubList); + if TenantMediaFilter <> '' then begin + TenantMediaSet.SetFilter(ID, TenantMediaFilter); + TenantMediaSet.DeleteAll(); + Commit(); // Ensure we keep the progress even on timeout (in case of large amounts of detached media). + end; end; end; @@ -185,6 +189,7 @@ codeunit 1928 "Media Cleanup Impl." SplitList: List of [List of [Guid]]; MediaOrphans: List of [Guid]; MediaOrphanSubList: List of [Guid]; + TenantMediaFilter: Text; begin if not TenantMedia.WritePermission() then exit; @@ -192,9 +197,12 @@ codeunit 1928 "Media Cleanup Impl." MediaOrphans := Media.FindOrphans(); SplitListIntoSubLists(MediaOrphans, 100, SplitList); foreach MediaOrphanSubList in SplitList do begin - TenantMedia.SetFilter(ID, CreateOrFilter(MediaOrphanSubList)); - TenantMedia.DeleteAll(); - Commit(); // Ensure we keep the progress even on timeout (in case of large amounts of detached media). + TenantMediaFilter := CreateOrFilter(MediaOrphanSubList); + if TenantMediaFilter <> '' then begin + TenantMedia.SetFilter(ID, TenantMediaFilter); + TenantMedia.DeleteAll(); + Commit(); // Ensure we keep the progress even on timeout (in case of large amounts of detached media). + end; end; end;