CRM 2011 Automated Deployment Tools – Hide Reports

Gayan Perera, 24 June 2012

At Magnetism we like to remove manual deployment tasks as much as possible to avoid errors or missed steps. We have built an automated deployment engine and one of the actions you can perform is the ability to hide certain reports.

For example, customers sometimes don’t want to see the out of the box reports. We use our deployment task runner to automatically hide them with every new release.

How does CRM control the visibility?

Dynamics CRM 2011 has a system/hidden entity called “reportvisibility” along with a “report” entity. These two entities are linked together via the “reportid” attribute/key.

To hide a report all we have to do is delete the “reportvisibility” record that’s linked to the report you’d like to hide.

Sample Code

private static string[] _reportsToDisable = new string[]
{
    "Account Distribution",
    "Account Overview",
};

var reports = (from rl in crm["reportvisibility"]
join r in crm["report"] on rl.Field<Guid>("reportid") equals r.Field<Guid>("reportid")
select new
{
    ReportId = r.Field<Guid>("reportid"),
    VisibilityId = rl.Field<Guid>("reportvisibilityid"),
    Name = r.Field<string>("name")
}).ToList(); 

reports.ForEach(a =>
    {
        if (_reportsToDisable.Contains(a.Name))
        {
            sdk.Delete("reportvisibility", a.VisibilityId);
        }
    }); 

In the next blog we’ll look at another automated deployment task.

Enjoy!