/// <summary> /// Method to build a CSV from a Collection of String representing Dynamics CRM Attributes/Fields. /// </summary> /// <param name="metadata">The XRM Metadata Object.</param> /// <param name="image">The Image Object.</param> /// <param name="entity">A String representing the Name of the Entity.</param> /// <returns>The CSV String of Attributes.</returns> private string GetAttributeCSV(XrmMetadata metadata, Image image, string entity) { try { AttributeCSV = string.Empty; if (image.Attributes != null && image.Attributes.Count != 0) { for (int i = 0; i < image.Attributes.Count; i++) { if (metadata.RetrieveAttribute(image.Attributes[i], entity).AttributeMetadata.LogicalName == image.Attributes[i]) { AttributeCSV += image.Attributes[i]; if (i != image.Attributes.Count - 1) { AttributeCSV += ","; } } else { throw new ArgumentException("The field does not exist in this entity."); } } } return(AttributeCSV); } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { throw; } }
/// <summary> /// Method to retrieve the SDK Message Filter Identifier. /// </summary> /// <param name="registration">The Registration Object.</param> /// <param name="step">The Step Object</param> /// <param name="service">The XRM Service.</param> /// <returns>The SDK Message Filter Identifier.</returns> private Guid GetSdkMessageEntityId(string xrmServerDetails, PluginStep step, XrmService service) { try { SdkMessageEntityId = new Guid(); XrmMetadata = new XrmMetadata(xrmServerDetails); PrimaryEntityMetadata = XrmMetadata.RetrieveEntity(step.PrimaryEntity); SecondaryEntityMetadata = new EntityMetadata(); if (!string.IsNullOrEmpty(step.SecondaryEntity)) { SecondaryEntityMetadata = XrmMetadata.RetrieveEntity(step.SecondaryEntity); } if (PrimaryEntityMetadata.MetadataId.HasValue) { QuerySdkMessageFilter = new QueryExpression { EntityName = SdkMessageFilter.EntityLogicalName, ColumnSet = new ColumnSet("sdkmessagefilterid"), Criteria = new FilterExpression() }; QuerySdkMessageFilter.Criteria.AddCondition("sdkmessageidname", ConditionOperator.Equal, step.PluginMessage); QuerySdkMessageFilter.Criteria.AddCondition("primaryobjecttypecode", ConditionOperator.Equal, PrimaryEntityMetadata.ObjectTypeCode); if (SecondaryEntityMetadata.MetadataId.HasValue) { QuerySdkMessageFilter.Criteria.AddCondition("secondaryobjecttypecode", ConditionOperator.Equal, SecondaryEntityMetadata.ObjectTypeCode); } else { if (!string.IsNullOrEmpty(step.SecondaryEntity)) { throw new ArgumentException("The secondary entity could not be found!"); } } SdkMessageFilterEntityCollection = service.RetrieveMultiple(QuerySdkMessageFilter); foreach (Entity entity in SdkMessageFilterEntityCollection.Entities) { SdkMessageFilter = (SdkMessageFilter)entity; if (SdkMessageFilter.SdkMessageFilterId.HasValue) { SdkMessageEntityId = SdkMessageFilter.SdkMessageFilterId.Value; } else { throw new ArgumentException("The message filter could not be found!"); } } } else { throw new ArgumentException("The primary entity could not be found!"); } return(SdkMessageEntityId); } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { throw; } }