Start using SortDate on Activities

Door Sidney Pourrier op

Since 2016 Microsoft has added the Sort Date attribute of type DateTime to the activity entity and to all child activities like Task, Phone Call, Email etc. This field can come in handy when there is the need to sort activities based on other criteria. For example, for an email activity, set the Sort Date equal to the Sent on date, otherwise set Sort Date equal to Modified on date. Or when a task or appointment is created but not completed use Due Date, when the task/appointment is completed use the Actual End. Default this field value is null and can be populated by using a custom Workflow or using Javascript or Business Rules (on each child activity form). But there are problems regarding those approaches.

  • 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 postoperation).
  • Javascripts or business rules are only triggered on form events. Completing them by using the button Mark as completed and activities created, updated by the Outlook client will not populate the field sortdate.

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
  • etc…

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.

Reacties op “Start using SortDate on Activities