The demo demonstrates how to manage relationships using OData bind syntax for writing and on-demand resolution for reading.
Writing a Lookup (Create/Update)
To link a record to another via a relationship, use the @odata.bind syntax on the relationship property name. To clear a lookup, set the property to null.
// Link contact to account using OData bind syntax
contact['parentcustomerid_account@odata.bind'] = `/accounts(${accountId})`;
// Clear a lookup by setting it to null
updates['parentcustomerid_account@odata.bind'] = null;
Reading a Lookup (On-demand Resolution)
When reading, Dataverse returns the GUID of the related record. To display a human-readable name, you must perform a second lookup using the related service.
// Step 1: Load contacts with the lookup GUID field
const contacts = await ContactsService.getAll({
select: ['contactid', 'firstname', '_msa_managingpartnerid_value']
});
// Step 2: Resolve the GUID to a display name when needed
const partner = await AccountsService.get(contact._msa_managingpartnerid_value, {
select: ['accountid', 'name']
});
// Writing
contact['parentcustomerid_account@odata.bind'] = `/accounts(${accountId})`;
// Reading
const partner = await AccountsService.get(contact._msa_managingpartnerid_value, {
select: ['accountid', 'name']
});