bcquality/microsoft/knowledge/data-modeling/share-mediaset-items-with-insert-not-field-assignment.md
Jesper Schulz-Wedde e81632b4be Complete AL review knowledge readiness
Fill telemetry and Query coverage, strengthen thin review domains, correct audited content defects, and add deterministic cheap-model evaluation and reference-integrity safeguards.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 9825b012-e653-496a-9310-c1f4b6f8ac27
2026-07-15 07:19:15 +02:00

1.5 KiB

bc-version domain keywords technologies countries application-area
all
data-modeling
mediaset
media
insert
field-assignment
tenant-media
delete-integrity
sharing
al
w1
all

Share MediaSet items with Insert instead of field assignment

Description

Media and MediaSet fields store IDs that reference tenant media system tables. When a record is deleted, the runtime looks for other references only in the same table and field index; it does not scan every table. Directly assigning a media-set field between different table types copies the ID without registering a separate media-set reference, so deleting one record can remove media that the other record still appears to reference.

Best Practice

When sharing media between different tables, iterate the source MediaSet and call Target.MediaSetField.Insert(Source.MediaSetField.Item(Index)), then modify the target record. Direct field assignment is safe only when source and target are the same record subtype and use the same field ID. This concern is about reference/delete integrity, not the separate performance cost of ModifyAll on tables with media fields.

See sample: share-mediaset-items-with-insert-not-field-assignment.good.al.

Anti Pattern

Target.Picture := Source.Picture; where the two variables refer to different table types or different media-field IDs. The code copies an opaque ID, but the platform does not know that two independent fields now share the media object.

See sample: share-mediaset-items-with-insert-not-field-assignment.bad.al.