Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

Share records to only SalesPerson using Plugin in Dynamics CRM

$
0
0

I want to share my contacts to only sales person who belongs to my child BU. I've done so far the following but I thought I am little de-tracked because of not nominating 'Sales Persons' into it. Any idea how can I share contact to my sales persons?

public void Execute(IServiceProvider isp)
        {
            IPluginExecutionContext context = (IPluginExecutionContext)isp.GetService(typeof(IPluginExecutionContext));
            ITracingService trace = (ITracingService)isp.GetService(typeof(ITracingService));
            IOrganizationServiceFactory factoy = (IOrganizationServiceFactory)isp.GetService(typeof(IOrganizationServiceFactory));
            IOrganizationService service = factoy.CreateOrganizationService(context.UserId);

            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
            {
                Entity contect = (Entity)context.InputParameters["Target"];
                Guid guid = ((EntityReference)contect.Attributes["createdby"]).Id;

                var createdReference = new EntityReference("systemuser",guid);

                var grantAccess = new GrantAccessRequest
                {
                    PrincipalAccess = new PrincipalAccess { 
                        AccessMask = AccessRights.ReadAccess,
                        Principal = createdReference
                    },
                    Target = new EntityReference("contect",contect.Id),
                };
                service.Execute(grantAccess);

            }
        }



Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>