Monday, September 19, 2011

Get a list of System and User Dashboards in CRM 2011

You can get a complete list of System and User Dashboard by:

public void InitializeDashboardList()
{
     this.GetSystemDashboard();
     this.GetUserDashboard();
}

private void GetSystemDashboard()
{
if (!User.HasPrivilege("systemform", AccessRights.ReadAccess, (IOrganizationContext)UserInformation.Current))
return;
var systemdashboard = this.RetrieveDashboard("systemform", new string[4]
{
"formid",
"name",
"isdefault",
"description"
});
}

private void GetUserDashboard()
{
if (!User.HasPrivilege("userform", AccessRights.ReadAccess, (IOrganizationContext)UserInformation.Current))
return;
var userdashboard = this.RetrieveDashboard("userform", new string[3]
{
"userformid",
"name",
"description"
});
}

private ApplicationEntityCollection RetrieveDashboard(string logicalName, string[] columns)
{
     QueryExpression query = new QueryExpression(logicalName);
     query.ColumnSet.AddColumns(columns);
     query.Criteria.AddCondition("type", ConditionOperator.Equal, (object)0);
     query.Orders.Add((object)new OrderExpression("name", OrderType.Ascending));
     return DataSource.RetrieveMultiple(query, (IOrganizationContext)UserInformation.Current);
}

No comments:

Post a Comment