Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
Use alternate keys with data integration scenarios to perform data operations when you don't know the primary key value of a Dataverse record. You can only use alternate keys for tables where they're defined. Most Dataverse tables don't have alternate keys unless you customize them to include alternate keys.
To understand how to define and identify alternate keys for a table, see the following articles:
Use either the Dataverse Web API or SDK for .NET to work with alternate keys.
When you use the Web API, you reference a specific record by using a URL. Then, use the POST, PATCH, or DELETE HTTP methods to perform the data operation. You also use URLs to set values for single-valued navigation properties by using the @odata.bind syntax, or as parameters to functions and actions.
The following table provides examples that show how to reference records by using relative URLs:
| Situation | Example |
|---|---|
| With a primary key | /accounts(00000000-0000-0000-0000-000000000001) ORaccounts(accountid=00000000-0000-0000-0000-000000000001)See following note about systemuser and team entity types |
| With single alternate key | /accounts(accountnumber='ABC123') |
| With multi-part alternate keys | /contacts(firstname='Joe',emailaddress1='abc@example.com') |
| With an alternate key that uses a lookup column | /accounts(_primarycontactid_value=00000000-0000-0000-0000-000000000002)When you define an alternate key for a lookup column, you must use the name of the corresponding Lookup Property. A lookup property follows the following naming convention: _<name of single-valued navigation property>_value. |
Note
Because of how systemuser and team entity types inherit from the principal entity type, you can't use a named primary key to reference these entities. The primary keys for both of these entities is ownerid, rather than systemuserid or teamid. The principal entity type doesn't support GET operations. More information: EntityType inheritance
Exceptions when using alternate keys with the Web API
Be aware of the following conditions and possible exceptions when using alternate keys:
If you specify a column that isn't defined as a unique key, an error occurs. The error message is:
The key in the request URI is not valid for resource 'Microsoft.Dynamics.CRM.<table logical name>'. Ensure that the names and number of key properties match the declared or alternate key properties for the resource 'Microsoft.Dynamics.CRM.<table logical name>'.Alternate key values can't include some special characters.
Alternate key values with the following characters
/,<,>,*,%,&,:,\\,?,+aren't supported. These special characters are reserved or structurally significant in a URL path segment. Dataverse will return an error if you send aGETrequest with these values within the parentheses of the URL. The workaround is not to retrieve a single record, but to use the alternate key values with$filterto retrieve a collection that contains the one record that matches the alternate key values.For example, instead of this request that fails:
GET [Organization URI]/api/data/v9.2/new_skts(new_name='M%26M')Use a
$filterquery:GET [Organization URI]/api/data/v9.2/new_skts?$filter=new_name eq 'M%26M'&$select=new_nameIf you only need to access the record, you can take the data from the first (and only) matching record in the
valuecollection returned. If you need to perform some other action, like updating or deleting the record, you can use this approach to get the ID of the matching record and then refer to the record conventionally using the ID value rather than the value of alternate keys.Note
Parameter aliases (
@param) don't work with alternate key syntax. Using a parameter alias in a key predicate returns a400error even for values without special characters. Use$filterinstead.
More information: Retrieve record using an alternate key
See also
Define alternate keys for a table
Use change tracking to synchronize data with external systems
Use Upsert to insert or update a record