hello, icreate a plugin in the serviceappointment entity , iwant to retrieve the resources in the service appointment , they are a user in crm , and in each user found, i will update the usersytem entity
i create this code but that's not work , the entity collection always empty, icouldn't retrieve the list of resources ;
so please help me i think a have an error for extract the list of resources
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "serviceappointment")
return;
try
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
//get the value of ressources
ColumnSet col=new ColumnSet(new string[] { "resources" });
var retrievedApprovalRequest = service.Retrieve(entity.LogicalName,entity.Id,col);
EntityCollection receiverIds=new EntityCollection();
receiverIds = retrievedApprovalRequest.GetAttributeValue<EntityCollection>("resources");
for (int i = 0; i < receiverIds.Entities.Count; i++)
{
ActivityParty ap = receiverIds[i].ToEntity<ActivityParty>();
String userid = ap.PartyId.Id.ToString();
Entity user = new Entity("systemuser");
user["domainname"] = userid;
//update the fields of usersyteme entity
service.Update(user);
}
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
catch (Exception ex)
{
tracingService.Trace("servicecalendarPlugin: {0}", ex.ToString());
throw;
}
}
}