Introduction
This is a small blog on How to create an Alternate Key using C# code.
Prerequisites
- D365 Technical Knowledge
- Entity and Field must be present
Description
As per the official documentation, we need to create an EntityKeyMetadata request and add basic information.
Sample Code.
string entityName = "account"; string fieldName = "apsmc_externalid"; string alternateKeyName = "apsmc_ExternalKey"; string alternateKeyDisplayName = "External Id"; EntityKeyMetadata entityKeyMetadata = new EntityKeyMetadata() { KeyAttributes = new string[] { fieldName }, SchemaName = alternateKeyName, DisplayName = new Label(alternateKeyDisplayName, 1033) }; CreateEntityKeyRequest createEntityKey = new CreateEntityKeyRequest() { EntityName = entityName, EntityKey = entityKeyMetadata, }; _client.Execute(createEntityKey);
References