retrieve resources in service activity c# RRS feed

  • Question

  • 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 =
                IPluginExecutionContext context = (IPluginExecutionContext)
                if (context.InputParameters.Contains("Target") &&
                    context.InputParameters["Target"] is Entity)
                    Entity entity = (Entity)context.InputParameters["Target"];               
                    if (entity.LogicalName != "serviceappointment")
                            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
                    catch (FaultException<OrganizationServiceFault> ex)
                        throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
                    catch (Exception ex)
                        tracingService.Trace("servicecalendarPlugin: {0}", ex.ToString());
    Wednesday, November 5, 2014 10:36 AM

All replies

  • Which stage and message is your plugin registered on ? I think the resources attribute is not populated in the pre-validate stage.

    It's also possible that the resources are updated via an Update, rather than set in the initial Create. Try registering the plugin on the Update message, and Post-operation stage

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Thursday, November 6, 2014 10:58 AM