Working With Many-To-Many Relationships

Microsoft Dynamics 365 lets you create custom many-to-many relationships between entities. The adapter exposes objects in the adapter object list that represent these custom many-to-many relationships. The adapter object name is the Relationship Entity Name you entered when you created the relationship in Dynamics 365.

The adapter object has three fields: A primary ID for the object and the object IDs for the two entities in the relationship. Adapter objects for these relationship entities support the seek, insert, and delete operations.

Consider a custom many-to-many relationship between account and contact entities. The name of the adapter object is new_account_contact. The fields for this adapter object are:

To add a relationship between an account and a contact in Dynamics 365, use a DTS file with an Insert step on the new_account_contactid object. Create data links with DBLOOKUPs to set the object IDs. For example:

The account name is source field 2. Create a formula on the data link of DBLOOKUP(S2, "T", "account", "name", "accountid").

The contact name is source field 4. Create a formula on the data link of DBLOOKUP(S4, "T", "contact", "fullname", "contactid").

To add a relationship between two Dynamics 365 records

  1. In the Workbench, create a DTS file with an Insert step for the relationship entity object. The adapter sets the primary ID for the object for you.
  2. Set the value of the object IDs for the two related records.

    The most straightforward way to do this is to have a data link on the object ID fields using the DBLOOKUP() function to derive the ID based on a value from your source data.

Alternatively, you can use one of the following:

See also

Reference