If you have the on-premise version, probably the fastest way to do this is to access the database table UserSettingsBase
and update the DefaultDashboardId
column to the guid of the dashboard you want each user to have. (Edit - just realized you're using CRM Online, so this is not applicable.)
You can accomplish the same in the API framework by instantiating the UserSettings
entity for each user, finding each user's appropriate roleid
, and updating the DefaultDashboardID
property of the UserSettings
entity. An example is below.
using (OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(new Uri("Your CRM Server"), null, null, null))
{
_serviceProxy.EnableProxyTypes();
using (OrganizationServiceContext osc = new OrganizationServiceContext(_serviceProxy))
{
var usersSettings = from u in osc.CreateQuery<SystemUser>()
join ur in osc.CreateQuery<SystemUserRoles>() on u.SystemUserId.Value equals ur.SystemUserId.Value
join r in osc.CreateQuery<Role>() on ur.RoleId.Value equals r.RoleId.Value
select new
{
id = u.SystemUserId.Value
, roleName = r.Name
};
foreach (var users in usersSettings)
{
UserSettings us = new UserSettings();
us.SystemUserId = users.id;
switch (users.roleName)
{
case "CEO":
us.DefaultDashboardId = Guid.Parse("2E3D0841-FA6D-DF11-986C-00155D2E3002"); //the appropriate dashboardid
break;
//case "Sales Person"
//case "..."
//default: ...
}
_serviceProxy.Update(us);
}
}
}