I would not recommend to perform the following code for every single entity, as the RetrieveEntityRequest is not the fastest. Perhaps it would be sensible to pre-set your system and set expected entities to be "Sending email (If an email field does not exist, one will be created)" setting on Entity via customisations. Alternately, retrieve entities metadata before you enter the loop, so your code does not repeat the same checks over and over. The following code should suit your exact code: else { //here we add generic code for any entity RetrieveEntityRequest retrievesEntityRequest = new RetrieveEntityRequest { EntityFilters = EntityFilters.Entity, LogicalName = entityName }; RetrieveEntityResponse retrieveEntityResponse =(RetrieveEntityResponse)_serviceproxy.Execute(retrievesEntityRequest); EntityMetadata isActivityParty = retrieveEntityResponse.EntityMetadata["IsActivityParty"]; if (isActivityParty == true) { String emailAddress = currentEntity.GetAttributeValue ("emailaddress"); if (!String.IsNullOrEmpty(emailAddress) { result.Add(emailAddress); } } } Thanks, Piotr
↧