Microsoft Dynamics CRM MVP Aaron Elder of Ascentium provides some tips and tricks.
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:
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:
1: -- Run this against your Org_MSCRM database
2: DECLARE @EntityYouAreTryingToModify VARCHAR(50)
3: DECLARE @AttributeYouAreTryingToDelete VARCHAR(50)
4: -- TODO: Update these to the entity and attribute you are working with
5: SET @EntityYouAreTryingToModify = 'invoke_employees'
6: SET @EntityYouAreTryingToModify = 'invoke_hardwaremacintoshdesktop'
7: SELECT WFD.WorkflowDependencyId AS 'workflowdependencyid',
8: WF.Name FROM WorkflowDependency AS WFD
9: -- Join out to the Workflow Table to get the Name of the Workflow
10: JOIN Workflow AS WF ON
11: WFD.WorkflowId = WF.WorkflowId AND
12: WF.StateCode = 1
13: WHERE
14: WFD.DeletionStateCode = 0 AND
15: WFD.DependentEntityName = @EntityYouAreTryingToModify AND
16: WFD.DependentAttributeName = @EntityYouAreTryingToModify AND
17: WFD.Type = 8 AND
18: 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)
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.
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.
Published Tuesday, December 30, 2008 8:35 AM by crmblog
No comments:
Post a Comment