Hi CRM Support,
I'm working on a code that will auto share opportunity record to specific number of users. I have it work correctly when i set a specific id of a user. However i'm experiencing an error when i fetch specific users from another entity.. error shows the following message
Please see my plug-in codes below:
//grant access test codes-------------------------------------------------------------------------------START//Fetch Users to that will have access to the opportunity
QueryExpression queryLeadcodeAssignee = new QueryExpression("nexus_nexus_leadcode_systemuser");
queryLeadcodeAssignee.ColumnSet = new ColumnSet(new string[] { "systemuserid" });
queryLeadcodeAssignee.Criteria.AddCondition("nexus_leadcodeid", ConditionOperator.Equal, ((EntityReference)PostImageForOpportunities["nexus_leadcode_lookup"]).Id);
queryLeadcodeAssignee.PageInfo.ReturnTotalRecordCount = true;
EntityCollection LeadcodeAssigneeEntity = service.RetrieveMultiple(queryLeadcodeAssignee);
foreach (Entity LeadcodeAssigneeEntityResult in LeadcodeAssigneeEntity.Entities)
{
var Rights = AccessRights.ReadAccess | AccessRights.WriteAccess ;
var sampleuser1 = new EntityReference("systemuser", ((EntityReference)LeadcodeAssigneeEntityResult["systemuserid"]).Id);//new Guid("E9007311-358D-E211-A12C-36D7C49CDBE8"));
var principalAccess = new PrincipalAccess
{
// Gives the principal read write access
AccessMask = Rights,
// Set the PrincipalAccess Object's Properties
Principal = sampleuser1
};
// Create the Request Object
var grantAcessRequest = new GrantAccessRequest();
// Set the Request Object's properties
grantAcessRequest.PrincipalAccess = principalAccess;
// Set the Target. In my case it is account record
var entityReference = new EntityReference("opportunity", PostImageForOpportunities.Id);
//throw new InvalidPluginExecutionException("EntityReference");
grantAcessRequest.Target = entityReference;
//Execute the Request
service.Execute(grantAcessRequest);
}
//grant access test codes-------------------------------------------------------------------------------END
Advance thank you for you help..
Regards,
Honey Dulatre