Skip to content

EslamEllaithy/xtb-dataverse-linktable-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Dataverse LinkTable Builder

Convert any out-of-box N:N (many-to-many) relationship in Microsoft Dataverse or Microsoft Dynamics 365 CRM into records of your own custom link table (intermediate entity).
Built as an XrmToolBox plugin for safe, repeatable migrations.


What it does

  • Reads all pairs from an existing N:N relationship’s intersect table.
  • Creates corresponding records in a custom link entity you provide (with two lookup columns).
  • De-duplicates source pairs in memory.
  • Optional “Skip existing links” check to avoid creating duplicates.
  • Uses ExecuteMultiple with a configurable batch size (≤ 1000) and read page size for speed.
  • Streams progress to a log pane.

⚠️ This tool does not create schema for you. You must have already created the custom link entity and its two lookup columns that point to the same target entities as the original relationship.


Scenarios Where a Custom Junction Table Fits You

  • Link-level attributes — Store extra data on the relationship itself (e.g., role, dates, quantity, notes).

  • Automation on link events — Trigger workflows/flows/business rules/plugins on create/update/delete of the link row.

  • Row-level security & ownership — Make the link User/Team-owned to secure, share, and audit per association.

  • Full auditing — Track changes to every field on the link, not just associate/disassociate events.

  • Reporting & analytics — Build views, charts, dashboards, and use calculated/rollup columns on the link.

  • Data quality & constraints — Enforce uniqueness with alternate keys (e.g., LeftId+RightId+Role) and de-dup rules.

  • Integration & migration friendly — CRUD and upsert via alternate keys are simpler than associate/disassociate calls.

  • Lifecycle & state — Add Status/Status Reason, approvals, soft-delete, or even a BPF to govern the relationship.

  • Flexible topology — Link to additional tables (owner/source/files), add more lookups, and attach files/notes directly.


Requirements

  • Microsoft Dataverse (online) or Microsoft Dynamics 365 CRM.
  • XrmToolBox (latest recommended).
  • Security:
    • Read on both related entities (Entity1 & Entity2 in the relationship).
    • Create/Read on the custom link entity (and Append/AppendTo as appropriate).
    • If using an application user, grant a role that covers the above privileges.

Quick start

  1. Connect to your Dataverse environment (XrmToolBox connection toolbar).
  2. In the tool:
    • Enter the Relationship (schema name), e.g. accountcontacts_association.
    • Click Get Relationship Details.
      • The tool shows First Entity and Second Entity logical names.
    • Fill these fields (they unlock after Resolve):
      • Link table (logical name) – your custom entity logical name (e.g. new_accountcontact).
      • First lookup column – lookup attribute on your custom entity that targets Entity 1.
      • Second lookup column – lookup attribute on your custom entity that targets Entity 2.
  3. Optional Settings (right side):
    • Page size (read) – page size when reading the intersect table (default 5000).
    • Batch size (create ≤ 1000) – ExecuteMultiple batch size (default 400).
    • Skip existing links – if checked, the tool pre-loads existing link records and skips any duplicates.
    • Save Settings / Load Defaults.
  4. Click Build link records (green button).
  5. Watch the log for progress and totals (e.g., “De-duplicated 12,345 → 12,100”, “Batch executed: ok=400, failed=0”, “Created 12,100 record(s)”).

Field mapping rules

  • For each pair (Entity1Id, Entity2Id) found in the N:N intersect table, the tool creates 1 record in your custom link entity:
    • Left lookup column = Entity 1 record reference.
    • Right lookup column = Entity 2 record reference.

Tip: If you want hard duplicate prevention, add a unique index (alternate key) on the custom link entity covering the two lookup columns. With Skip existing links on, the tool avoids creating duplicates; the key enforces uniqueness at the platform level too.


Best practices

  • Test first in a sandbox environment.
  • Choose conservative batch sizes (≤1000) and run off-hours for very large datasets.
  • Keep Skip existing links enabled for idempotent re-runs.
  • After migration, consider:
    • Updating forms/views/business logic to use the new link table.
    • Optionally removing the OOB N:N, if that’s your end state.

How to find the relationship schema name

  • In the Solution Explorer (classic), open the parent entity → N:N Relationships → open the relationship → copy Schema Name.
  • Or use the Metadata Browser (e.g., XrmToolBox plugin) to search relationships and copy the schema name.

Troubleshooting

  • “Relationship ‘X’ is not Many-to-Many or was not found.”
    Ensure the schema name is correct and that it’s truly an N:N relationship (not 1:N or N:1).

  • Created 0 record(s)
    Possible causes:

    • The N:N contains no data.
    • All pairs already exist in your custom link entity and Skip existing links is on.
    • The left/right lookup columns point to the wrong target entities.
  • Batch failures in log
    Reduce Batch size. Verify security privileges on the custom link entity.

  • Slow runs
    Try smaller Page size (e.g., 2000–5000) or smaller Batch size (200–500). Close other heavy tools during the run.


Disclaimer

This tool performs bulk creates. Use responsibly, validate in non-production first, and ensure you have appropriate backups and security permissions before running in production.

About

Convert Dataverse N:N relationships into records of a custom link (junction) table.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages