The curse of the deleted workflows

When you’re following a development process including at least a development and production environment, then you might end up in a scenario where you have deleted a workflow from the production environment and then want to import a solution containing the very same workflow.

In some scenario’s you will find that this results in the error message:

0x80041103: Workflow' entity doesn't contain attribute with Name = 'Workflowid'.

Though the error message isn’t valid at all, the workflow entity definitely has the attribute Workflowid, there is an explanation for the error.

What happens when you enable a workflow, is that a copy of the workflow is created in the database, called a ‘Workflow activation’. It is this copy of the workflow that is being used when a workflow is executed. This is useful for when the workflow is being changed, the current workflows will then continue running against this copy of the workflow. Michael B. Scott describes this pretty well in a response on this forum:

He also describes that it takes a while (max 24 hours), before the workflow activation records get deleted when they’re not used anymore. And it is exactly the existence of this workflow activation that causes the error message. This means that in a happy scenario the error should magically disappear within 24 hours.

But, sometime it doesn’t.

In that case there are still references to the workflow activation record. You can find these when searching for system jobs carrying the same name as the name of the workflow. Most likely these are the instances of the workflow that didn’t end with a success state, such as cancelled or failed workflow executions. After deleting these, then another 24 hours later, the workflow activation record should get removed.

But, how to delete these? You are lucky if this works through the CRM UI, but this can throw error messages as well as the related workflow doesn't exist anymore. In that case a bulk delete can give you the answer. Note: I would always strongly favor the CRM UI approach as this handles as much cleaning as possible for you.

But if that doesnt'work and you do have access to the database, then I have some SQL queries that can help identify the records or even clean them server-side.

-- select all records having a non existing parent (most likely only workflow activation records)
Select name, workflowid, parentworkflowid, * from Workflowbase w
where parentworkflowid not in (select workflowid from Workflowbase)
order by 1

-- select all system jobs related to the selected workflow activation records
select asyncoperationid, WorkflowActivationId, WorkflowActivationIdName, CorrelationId, statecode, CreatedOn, completedon, regardingobjectid, regardingobjectidname, regardingobjecttypecode
from AsyncOperation
where WorkflowActivationId IN
       (Select workflowid from Workflow w
       where parentworkflowid not in (select workflowid from Workflow))
order by workflowactivationid, CompletedOn

-- find out how many workflowlog records (basically steps in a workflow) are related to the workflow instances
select count(*) from workflowlog
where AsyncOperationId IN
       (select asyncoperationid from AsyncOperation
       where WorkflowActivationId IN
             (Select workflowid from Workflow w
             where parentworkflowid not in (select workflowid from Workflow)



Packers And Movers Bangalore said...

Packers and Movers Bangalore as a Services providing company can make all the difference to your ###Home Relocation experience. Bangalore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a ✔✔✔ Household Shifting, ***Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges @

Packers And Movers Bangalore

steve said...

معلومات مفيدة جدا شكرا لك يمكنك زيارة :
شركة نقل عفش من جدة الى الامارات
شركة نقل عفش من جدة الى الاردن
شركة نقل عفش من جدة الى الدمام
شركة نقل عفش من جدة الى المدينة المنورة
شركة نقل عفش من جدة الى الطائف
شركة نقل عفش من جدة الى البحرين

usman said...

We as QuickBooks Support Phone Number +1-844-233-5335 team provide our matchless support for the issues in QuickBooks to its users worldwide. It goes without saying that QuickBooks is one of the most helpful accounting software presents in the current time. Read more- & visit us-

usman said...

QuickBooks has completely transformed the way people used to run their business earlier. In order to get used to it, one should welcome this positive change. Supervisors at QuickBooks Support Phone Number 800-417-3165 have trained all their executives to combat the issues in this software. Read more- & visit us-

usman said...

QuickBooks is one of the most widely used accounting software, it also offers you a range of versions. We provide help at QuickBooks Payroll Support Phone Number +1-844-233-5335 to deal with the issues in this QuickBooks version. Read more- & visit us-

usman said...

Our support team at QuickBooks Payroll Support Phone Number +1-800-417-3165 helps you deal with the issues that pop up in this software. When it comes to errors, there are so much that you may face. Read more- & visit us-