bcquality/microsoft/knowledge/data-modeling/share-mediaset-items-with-insert-not-field-assignment.md
Jesper Schulz-Wedde 2b5550c346
Some checks failed
Validate knowledge index / validate-index (push) Has been cancelled
Validate AL review fixtures / validate-review-fixtures (push) Has been cancelled
Validate frontmatter and structure / validate (push) Has been cancelled
Improve partner onboarding and documentation navigation (#174)
Lead with a complete plugin quick start and add task-oriented usage, troubleshooting, customization, and contribution guides. Preserve the broader plugin framing, correct conflicting contract guidance, support Agents folder reviews, and align repository validation. Convert existing sample references to clickable links without changing knowledge rules.

Co-authored-by: Jesper Schulz-Wedde <jesper.schulzwedde@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
2026-09-09 17:31:03 +02:00

1.7 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.