Changes which are need to be made:-
-
Change in the security role
-
Customization of all the CRM form (Home page, Form Data Entry page, Form grid page)
-
Changing the views according to the roles
Change in the security role
Change in the security role is made in the Setting → Administration → Security Role.
The privilege can be given on the basis of
-
None:- That privilege will not be given
-
User :- That user will able to do operation on his/her records only.
-
Business Unit :- That user will able to do operation on his/her business unit records only.
-
Parent Business Unit :- That user will able to do operation on his/her parent business unit records only.
-
Organization :-That user will able to do operation on all records.
Customization of all the CRM form (Home page, Form Data Entry page, Form grid page)
There are two things which are needed to be changed:-
-
Ribbon Button
-
Site map
Ribbon button Customization
Steps(Example :- Advance Find):-
-
Create an entity in the name of the button (new_advancefindrole)
-
Give the permission to the entity(new_advancefindrole) in the Security Role under custom entity(Read).
-
Open the ribbon solution in a ribbon editor.
-
Add a new button and copy the (detail,action , display rule, enable rule ) from advance find to new button
-
Add a new display rule
-
Entity Privilege rule
-
Give the name of the entity( new_advancefindrole)
-
Privilege depth :- Basic
-
Privilege type :- Read
-
Default :- true
-
Invert Result :- false
-
Hide the original advance find button(we can’t change the display rule in original advance find as it is managed)
-
save the customization
-
give permission under security role to entity(new_advancefindrole) to read to show in different roles.
Site Map
Steps(Example :- Settings):-
-
Create an entity in the name of the button (new_settingsrole)
-
Give the permission to the entity(new_settingsrole) in the Security Role under custom entity(Read).
-
Export the “Site map” solution from the CRM
-
Open Customization.xml in an xml editor
-
Find “Area Id=<AreaName>(Ex :- Settings)” tag. Paste the Code Below.
<SubAreaId=“nav_administration“ResourceId=“Homepage_Administration“DescriptionResourceId=“Administration_SubArea_Description“Icon=“/_imgs/ico_18_administration.gif“Url=“/tools/Admin/admin.aspx“AvailableOffline=“false“ >
<PrivilegeEntity=“new_settingsrole“Privilege=“Read“ />
</SubArea>
-
Paste this code under every subarea of the settings
-
Save the solution zip it , import it and publish it
-
give permission under security role to entity(new_settingsrole) to read to show in different roles.
Changing the views according to the roles
Showing the view according to the role. There are two method in which this can be done :-
-
By plug-in
-
By creating personal view and sharing it with team
By Plug-in
Steps:-
-
Create the Plug-in with following code.
-
By this plug-in the view Starting from “My” will not be shown
-
Register it :-
-
Message :- RetriveMultiple
-
Primary Entity :- savedquery
-
Eventing :- Per-operation
-
Execution Mode:- Synchronous
-
Deployment:- Server
-
Plug-in Code:-
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using Microsoft.Crm.Sdk;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Crm.Sdk.Messages;
namespace Excitation.PluginHideSystemViews
{
publicclassCheckView : IPlugin
{
publicvoid Execute(IServiceProvider serviceProvider)
{
try
{
// Obtain the execution context from the service provider.
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
// Obtain the organization service reference.
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
// The InputParameters collection contains all the data passed in the message request.
if (CheckRole(context.UserId, “Salesperson”, service))
{
if (context.InputParameters.Contains(“Query”) == true && context.InputParameters["Query"] isQueryExpression)
{
QueryExpression qe = (QueryExpression)context.InputParameters["Query"];
if (qe.EntityName == “savedquery”)
{
if (qe.Criteria != null)
{
if (qe.Criteria.Conditions != null)
{
/*The query is edited to look at views not starting with “My” at the begining of the View Name*/
ConditionExpression queryCondition = newConditionExpression(“name”, ConditionOperator.NotLike, “My%”);
qe.Criteria.Conditions.Add(queryCondition);
//context.InputParameters.Properties[ParameterName.Query] = qe;
context.InputParameters["Query"] = qe;
}
}
}
}
}
else
{
QueryExpression qe = (QueryExpression)context.InputParameters["Query"];
context.InputParameters["Query"] = qe;
}
}
catch (Exception e)
{
}
}
//check if the user belongs to the specified role….
privatestaticbool CheckRole(Guid UserGuid, string SecurityRole, IOrganizationService CrmService)
{
#region Retrieve records from an intersect table via QueryExpression
//Create Query Expression to fetch Role Entity
QueryExpression Query = newQueryExpression()
{
//Setting the link entity condition and filter condition criteria/
LinkEntities =
{
newLinkEntity
{
LinkFromEntityName = “role”,
LinkFromAttributeName = “roleid”,
LinkToEntityName = “systemuserroles”,
LinkToAttributeName = “roleid”,
LinkCriteria = newFilterExpression
{
FilterOperator = LogicalOperator.And,
Conditions =
{
newConditionExpression
{
AttributeName = “systemuserid”,
Operator = ConditionOperator.Equal,
Values = { UserGuid }
}
}
}
}
}
};
Query.EntityName = “role”;
Query.ColumnSet = newColumnSet(true);
// Obtain results from the query expression.
EntityCollection UserRoles = CrmService.RetrieveMultiple(Query);
// Searching for a specified Security Role into the list
String test = “”;
test = UserGuid + ” \n”;
foreach (Entity UserSecurityRole in UserRoles.Entities)
{
test += (String)UserSecurityRole.Attributes["name"] + ” \n”;
if ((String)UserSecurityRole.Attributes["name"] == SecurityRole)
{
returntrue;
}
}
Entity testE = newEntity(“new_transfer_opp”);
testE.Attributes["new_name"] = test;
CrmService.Create(testE);
if (UserRoles.Entities.Count == 0)
{
//return false as the role does not present
returnfalse;
}
else
{
returnfalse;
}
#endregion
}
}
}
By creating personal view and sharing it with team
Steps(Example:- Sale manager):-
-
Create a team(Sales manager) and add user to that team (Team is added under Administration)
-
Create a view by Advance find Save that view
-
Go to saved view and share the view to the team you want to see that view.
