Monday, April 18, 2016

Creating a custom filter for advanced system reporter in Sitecore

The advanced system reporter module for Sitecore is a great way to provide reporting, in a similar way to the out-of-box broken links report. After installation the module comes with a number of pre-defined reports, along with scanner and filter, but there can be a need to customize for specific reports the business needs.

In this case I have written a custom filter to filter by template name. The business need for this one would be to use an existing report, but filtered on a specific template (for example media releases).

namespace MyProject.Reports
{
    public class TemplateNameFilter : BaseFilter
    {
        public string TemplateName { get; set; }
        public override bool Filter(object element)
        {
            Item item = null;

            if (element is Item)
            {
                item = element as Item;
            }
            else if (element is ItemWorkflowEvent)
            {
                item = (element as ItemWorkflowEvent).Item;
            }

            if (item != null)
            {
                if (item.TemplateName == TemplateName)
                {
                    return true;
                }
            }

            return false;
        }
    }
}

Once deployed to Sitecore, the custom filter can be created:


A custom parameter also needs to be created:



Now the filter can be added to any advanced system report.

No comments:

Post a Comment