Just do it : Deleting attributes that are in use by running Workflows 
This post is also available here.

Recently, we had the need to delete several attributes from an entity we had created (Employee).  Normally this is a very straight forward affair in Microsoft CRM.  You simply remove the field from the Form and Grids and they using the Entity Editor select the attribute and hit “delete”.  In this case, the attributes in question, were being used by workflow.  Unfortunately, the error you get from CRM is not terribly helpful:

Error: This attribute cannot be deleted because it is used in one or more workflows.  Cancel any system jobs for workflows that use this attribute, then delete or modify any workflows that use the attribute and then try to delete the attribute again.

While the steps to take are indeed correct and actually rather useful, the error does nothing to tell you which Workflow is causing the problem.  This was especially a problem for us because we happened to have almost 20 workflows running on the Employee entity and unpublishing and hunting through each of these would have been a real pain.  Of course with a little bit of SQL, there is a better way:

-- Run this against your Org_MSCRM database

DECLARE @EntityYouAreTryingToModify VARCHAR(50)
DECLARE
@AttributeYouAreTryingToDelete VARCHAR(50)

-- TODO: Update these to the entity and attribute you are working with
SET @EntityYouAreTryingToModify = 'invoke_employees'
SET @EntityYouAreTryingToModify = 'invoke_hardwaremacintoshdesktop'

SELECT    WFD.WorkflowDependencyId AS 'workflowdependencyid',
        WF.Name FROM WorkflowDependency AS WFD

    -- Join out to the Workflow Table to get the Name of the Workflow
    JOIN Workflow AS WF ON
        WFD.WorkflowId = WF.WorkflowId AND
        WF.StateCode = 1

    WHERE
        WFD.DeletionStateCode = 0 AND
        WFD.DependentEntityName = @EntityYouAreTryingToModify AND
        WFD.DependentAttributeName = @EntityYouAreTryingToModify AND
        WFD.Type = 8 AND
        WF.DeletionStateCode = 0

This query, will return a list of the Workflows that are currently published and that have a dependency to the field you are trying to delete.

Now that you know what Workflows are causing the problem, the steps to fix this are pretty simple:

  1. Unpublish the Workflow(s)
  2. Remove the dependency (In the “Properties” of a Step, the “Record Attributes Change” list, etc)
  3. Re-publish your Workflow
  4. Delete your attributes

Now, if you happen to instead:

  1. Unpublish the Workflow(s)
  2. Delete the Attribute
  3. And try to re-publish the Workflow(s)

An error has occurred

You are going to run into a “Generic” error when you try to re-publish the Workflow.  This is because the CRM delete attribute process is smart enough to delete the dependencies from part of the Workflow, but not all.  If you find yourself in this situation, don’t worry… just open the Workflow editor using the User Interface, remove the dependency and “re-save” it.

Workflow Editor

The Workflow UI XML and various other XMLs will get “re-updated” with the dependency removed.  You can now re-publish the workflow and all should be well.

Cheers,

 

This posting is provided "AS IS" with no warranties, and confers no rights.

Comments
No Comments Available
Add a New Comment
Name

Email Address

Url

Comment