Microsoft Dynamics CRM

{Quick Tip} Check organization name in Dynamics CRM Plugin

In a rather interesting scenario recently there was a need to validate organization name in a plugin. This was for a reusable component used for several of our clients and we wanted to make sure that the organization that can use this component is amongst our clients.

So, we needed a way to validate organization name that are using this plugin and then only allow the use of the component in case we have installed the component.

We needed a code solution!

clip_image001

On some research came to know about the following property in plugin context:

 

   public void Execute(IServiceProvider serviceProvider)

        {

            #region initialize

            IPluginExecutionContext context;

            ITracingService tracingService;

            IOrganizationServiceFactory serviceFactory;

            IOrganizationService service;

 

            // Get a reference to the tracing service.

            tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

 

           // Obtain the execution context from the service provider.

            context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

if (context.OrganizationName != “organisationname”)

            {

//Run code here

             

            }

       

        

       }

 

Other 2 interesting properties I wanted to tell about below:

context.IsExecutingOffline (Check if plugin is executing offline)

context.OperationCreatedOn (Check operation creation date)

Hope it helps and Happy CRMing!

If you want to know more on Dynamics CRM, just get in touch.

Do not forget to share! Sharing knowledge is true power!


Check this out

About the Author:

image

Twitter: https://twitter.com/msdynamicsblog
LinkedIn: https://www.linkedin.com/in/deepesh-somani-00296932

Google Play Store:

https://play.google.com/store/apps/details?id=com.dynamicsofdynamicscrm.msdynamicsblog&hl=en

Advertisements
Microsoft Dynamics CRM

{Code Tip} Control Activate/Deactivate Privilege on CRM entities

Requirement: Client wants the ability to control Activate/Deactivate privilege on CRM entities.

Solution: Out of box, there is no ability to control Activate/Deactivate privilege. This is one of the classical CRM problems.So this one will require a little code solution.

image

In the proposed solution, I suggest two approaches:

· Create Additional Configuration entity to collect the permissions by role at Entity level and then allow/disallow Activate/Deactivate

· Create a Team for users : If user is part of the team user has privileges to Activate/Deactivate the record, else doesn’t have the privilege

Thereafter Plugin will read the configuration or team information and then allow/disallow Activate or Deactivate.

Finally, A decision was made to choose the team approach.

Here is the code to be used in the plugin then

using (var serviceContext = new OrganizationServiceContext(service))

{

if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is Entity)

{

Entity entity = (Entity)context.InputParameters[“Target”];

if (!IsTeamMember(new Guid(“Team Guid”), context.UserId, service))

{

throw new InvalidPluginExecutionException(“You do not have permission to Activate/Deactivate. Please contact System Administrator”);

}

}

}

Here is the IsTeamMember method code:

public static bool IsTeamMember(Guid teamID, Guid userID, IOrganizationService service)

{

QueryExpression query = new QueryExpression(“team”);

query.ColumnSet = new ColumnSet(true);

query.Criteria.AddCondition(new ConditionExpression(“teamid”, ConditionOperator.Equal, teamID));

LinkEntity link = query.AddLink(“teammembership”, “teamid”, “teamid”);

link.LinkCriteria.AddCondition(new ConditionExpression(“systemuserid”, ConditionOperator.Equal, userID));

var results = service.RetrieveMultiple(query);

if (results.Entities.Count > 0)

{

return true;

}

else

{

return false;

}

}

Next, register this on Update of status field:

clip_image002

Now until the users are added to the Team, they will not be able to Activate/Deactivate record.

Hope it helps and Happy CRMing!

If you want to know more on Dynamics CRM, just get in touch.

Do not forget to share! Sharing knowledge is true power!


Check this out

Twitter: https://twitter.com/msdynamicsblog
LinkedIn: https://www.linkedin.com/in/deepesh-somani-00296932

Google Play Store:

https://play.google.com/store/apps/details?id=com.dynamicsofdynamicscrm.msdynamicsblog&hl=en