Okay, this post is a response to a good question made by someone on the Microsoft Dynamics CRM forum (for Partners).
The initial question was:
“Hi All,
When an opportunity is cancelled, the activities (tasks, appointments, etc.) are not being flagged as cancelled and staying considered as “open” items. We need to find a solution that when an opportunity is closed (or cancelled) that all associated activities tied to that opportunity be deleted. Can i automate the above process? I tried using workflow, but i am not able to trigger an Activity record.
Regards,
VP”
A response from Dylan Haskins pointed to a really cool workflow plugin called ‘Distributed Workflow’ and available on Codeplex here.
In this post, I will show how to use this plugin in the particular situation stated above.
- Download the plugin (which is basically a DLL) and copy it on your CRM server
- Launch the ‘Plugin Registration tool’, given with the Microsoft Dynamics CRM SDK (available here)
- In the registration tool, you simply need to register the plugin and that’s it!
- When this step is done, a new workflow step will be available in your workflow rules:
- So, let’s create a new workflow rule that will target an opportunity, but first you have to know the type of relationship between an activity and an opportunity: start by going to the “1:N relationships” in the opportunity entity and write down the name of the relations between the various activities and the opportunity
- Now create a new workflow rule against the phone call entity and simply add a workflow step that changes the phone call’s status to ‘Cancelled’; this workflow rule must be available to run ‘on demand’. Publish it
-
Now that you have your ‘related’ workflow rule, let’s create another one but this time you must target the opportunity entity
-
This workflow should run whenever you change the opportunities’ status reason to ‘Cancelled’, so we should first verify the status reason and then launch the ‘on demand’ workflow rule, based on the 1:N relationship. Don’t forget to publish your workflow once it is done.
-
In our case, the ‘Distribute Workflow (1:N)’ properties should be set to this:
Before the workflow rules were deployed, this is what it looked like when an opportunity was closed or cancelled:
You can see that all the activities are still open!
Now that we have deployed our new workflow rules, this is what it looks like (which is much better ):
Workflow running
Phone call activity now cancelled as well!
NOTE: If you want to cancel other activity types, you have to repeat the steps 5 & 6 to create a workflow rule for each activity type; then, you would modify the opportunity workflow rule to take into account the other ‘on demand’ workflows
HTH!