"The automation state and plan has not been found" errors in log


Description

After replacing the existing analytics MongoDB database with a clean one, for example, while refreshing non-production environment or deploying existing solution to different environment, the following exception can appear in the Content Management instance's log files when sending triggered emails in EXM:

1 13:10:20 ERROR Failed to enroll a contact in the engagement plan.
Exception: Sitecore.Modules.EmailCampaign.Exceptions.EmailCampaignException
Message: The automation state for contact b99e1503-08c4-47cd-b685-763c52f9a305 and plan cec5f2cd-232d-4ce4-ad5f-9f78c4d73754 has not been found.
Source: Sitecore.EmailCampaign
   at Sitecore.Modules.EmailCampaign.Core.Analytics.AutomationStatesManager.EnrollOrUpdateContact(Guid contactId, Guid planId, String stateName, EcmCustomValues customValues, String[] validStates)
   at Sitecore.Modules.EmailCampaign.Core.Dispatch.DispatchManager.EnrollOrUpdateContact(Guid contactId, DispatchQueueItem dispatchQueueItem, Guid planId, String stateName, EcmCustomValues customValues)
   at Sitecore.Modules.EmailCampaign.Core.Dispatch.DispatchTask.OnSendToNextRecipient()

This issue is caused by missing engagement plan documents in the AutomationStateDefinition collection of the analytics database. It affects EXM 2.2 and later versions.

Solution

Open the /sitecore/admin/DeployDefinitions.aspx page to deploy all necessary xDB information to the analytics database.