We all know Alternate Key is used for the unique identification of an entity records in Dynamics 365 in the place of the primary key. The alternate key can be a combination of more than one attributes in Dynamics 365. Using alternate key user can identify a unique record in the system.
In this blog, will discuss how to move the Alternate key of a custom entity, from the source environment to target environment as a Managed Solution without failure.
Recently, we came across below scenario,
Where, we created Test solution in the source environment. And within the solution created a new custom entity, a custom field and also the Alternate Key.
Then we exported the solution as a Managed from source environment and imported it on the target environment, the status of alternate key remains as pending and it remains pending forever.
And we were getting below error on system job (Exception: Event failed due to an exception))
The cause of this issue was as below;
If a custom entity does not exists in the target environment, then the activation process of Alternate key fails for almost 75% times. The activation of the Alternate Key never fails for OOB entities and custom entity (if a custom entity already present in target environment).
After some research and play around we found the below solution:
We created a Test solution and added our custom entity (X). Then we created a patch from Test solution, where we added the alternate key.
Follow the steps below
In our custom entity (X), we created one custom field and also the Alternate key.
Then we have created a Test solution on source environment, in that we added custom entity (X) and the custom field. After that, we exported this solution form source environment and Imported into the target environment.
Then create a patch from a Test solution on source Environment, in that patch we added only Alternate Keys of that Custom Entity. After that Export that patch and Imported on target Environment.
The user can also activate alternate key manually in Dynamics 365.
Open Alternate Key Records.
We searched records in System job with the name equal to “Create index for (Alternate Key Name) Key for entity (Entity Name)”, and delete those system job records which are failed to execute.
To activate Alternate Key, Open Alternate key view and select the key from grid and click on “More Action” and select “Reactivate Key” option.
To avoid “Exception: Event failed due to an exception” User needs to ensure that the custom entity should be present in target environment, before moving the Alternate Key of a custom entity from source environment. Otherwise they have to activate alternate key manually.