Workflow Error!

Workflow X++ Error

Today I’m sharing a fix I recently applied to a tier 2 sandbox Dynamics 365 F&SCM system deployed and running with Contoso demo data.

Workflow Stopped Error

Users reported all workflows, no matter what the record type, ending while reporting the same error:

Stopped (error) x++ Exception: cannot create a record in Alerts - Event inbox data (EventInboxData). Inbox ID: -some-record-id- . The record already exists

I’m pretty sure this error is caused by the Contoso demo data shipping with some junk in the Event Inbox table. I haven’t checked on a fresh Contoso demo dataset, so that assumption could be wrong. Regardless of why it occurred, it needed fixing.

The Fix

The issue was reported on a tier 2 environment, if you are also running and looking to fix this on a tier 2, the first step is to gain access to the database. This guide will help you gain access from LCS:

Dynamics 365 F&O: Gain Database Access on a Tier 2 Environment (LCS)

If you are fixing this on a cloud hosted dev environment, open up SSMS when connected to the VM by remote desktop, and connect to the local database.

Running the following query will give you a list of the event inbox rows which are causing duplication issues. Substitute the record ID with the record ID 1 digit less than the record ID in the workflow error above (or just adjust this query to be greater than or equal to, both methods will work).

View Event Inbox Records

SELECT TOP(1000) [DATA]
    ,[DATATYPE]
    ,[INBOXID]
    ,[RECVERSION]
    ,[RECID]
 FROM [dbo].[EVENTINBOXDATA]
 WHERE INBOXID > -the-recid-before-your-rec-id-
 ORDER BY INBOXID DESC

If for some reason you need to take some care with this data, you should make sure you have a backup before the next step. If it is contoso demo and you don’t care (like I didn’t), you can delete all the offending records. If this isn’t a contoso demo data issue, it will hopefully be 1 or 2 records which nobody will miss from the event inbox, as its only really a notification, and not a critical transaction for workflow. If it is the contoso issue, you may have a lot of records over the offending RecId, and need to delete all of them.

Delete Event Inbox Records

DELETE FROM [dbo].[EVENTINBOXDATA] WHERE INBOXID > -the-recid-before-your-rec-id-

And thats it. The records which have used the RecID which workflow is trying to create in the Event Inbox table are deleted, and normal workflow can resume.

The final step is to head back to your workflow records in error, and click resume.

Resume Workflow

If everything has gone smoothly, the workflows stopped in error will all resume normally.