Sort Activities by Custom Date fields on the Social/Activity Pane

By | January 27, 2017

Sort Date by Custom Date Fields

Introduction:

Dynamics 365 added a new “Sort Date” field (attribute) in Activity entity. With the addition of this new attribute, we can now set the Sort Date field as per customer requirement.

You can now sort the activities on social pane in Dynamics 365. However, the fields shown there are only the ones present on the activity pointer. We cannot add custom field to the activity pointer.

Suppose if we have a requirement where we want to sort activities based on custom field then “Sort Date” field is the best option to fulfil this need.

Where and how to use Sort Date field?

For example, we have a requirement where we want to sort our activities as per their approval date. The approval date is a custom field added to the “Task” entity.

To ensure that the tasks are listed on the social pane sorted by “Approval date”, we can set the Sort Date field with the approval date through a quick customization. We can set this field by using business rule, plug-in or writing a script.

Setting Sort Date field by writing a Script:

We can add our script on the Task Approval Date field. Therefore, when the approval date changes, it will trigger the script and set the Sort Date as approval date.

function ApprovalDate_OnChange() {
    var functionName = "ApprovalDate_OnChange";

    try {
         //Get Task activity Approval date
        var approvalDate = Xrm.Page.getAttribute("new_approvaldate").getValue();

        //check if Approval date is not null 
        if (approvalDate != null && approvalDate != undefined) {

            //Set Sort Date field as approval date
            Xrm.Page.getAttribute("sortdate").setValue(approvalDate);
        }
    } catch (e) {
        throw e;
    }
}

Setting Sort Date field by using Business Rule:

We can set the Sort Date field using business rule as shown in below screenshot.

Sort Activities by Custom Date fields on the SocialActivity Pane-Dynamics CRM

Note: Since the custom field was added only on the Task entity, you will need to add a custom business rule for all other activities to populate the Sort Date field with the value appropriate for those activity types.

With the Sort date now set for all the activity types, we can use this field in Activity Pane for sorting the activities as per the criteria we have set.

Sort Activities by Custom Date fields on the SocialActivity Pane-Dynamics CRM

Conclusion:

Use the Sort Date field on the ActivityPointer to sort your activities by custom date fields on activities.

Spanish, German, French, Portuguese, and Turkish – Map analytics within Dynamics 365/CRM now in language of your choice!