- When using a synchronous workflow the field will not be populated when the activity is set to completed due to it’s readonly property (A synchronous workflow runs in post–operation).
The only consistent solution for this requirement is to write a plug-in. In this blog I will show u how to do this with a simple plug-in written in C#.
Step 1 Create a new Solution.
Once u have created a new solution add the entity named Activity and select the views which u want to add the field Sort Date to. In my case I added the field to the system views named All activities and Closed Activities.
Step 2 Add the field Sortdate to the view(s).
Add the attribute Sort Date by clicking on the button Add Columns.
When the field is included use the button Configure Sorting and set the picklist Sort By to Sort Date and the option Descending.
Step 3 Write the C# plugin
Now it’s time to write the plug-in based on the requirements I described above. This is my version of the plugin written in C#.
Don’t shoot me on this piece of code. I kept the code simple, without the use of the preImage attributes and handling them.
Step 3 Register the plugin
Once u have build the CRM plug-in, register it in CRM with the steps below using the PluginRegistration tool.
- Create Email
- Update Email
- Create Task
- Update Task
- Create PhoneCall
- Update PhoneCall
- Create Appointment
- Update Appointment
- Create Letter
- Update Letter
While creating the update steps set the Event Pipeline Stage of Execution to PreOperation and Execution Mode to Synchronous.
Step 4 Time to test the plugin
Now that all required steps are registered u can start testing the plugin. At first we want the value of the Sort Date to be the same as the value of Due Date. So start creating an appointment, task or phonecall but do not Mark it as complete yet.
As u can see in the image below the column Sort Date is equal to the column Due Date.
When the activities are marked as complete the Sort Date will be the same as the column Actual End.
Step 5 Ready to Deploy
Now the plug-in is working correctly according to the requirements, the attribute Sort Date can be configured in the other views. Also the activity panes on accounts and contacts can be changed to order on the Sort Date instead of the Modified On date.
Add the plug-in and all the required steps to the solution and you’re good to go.