public CRMEntityMetadata CRMGetEntityMetadata(CRMEntityMetadata entitytype) { OrganizationServiceProxy _serviceProxy; Microsoft.Xrm.Sdk.Metadata.EntityFilters filter = entitytype.IncludeAttributes ? Microsoft.Xrm.Sdk.Metadata.EntityFilters.Attributes : Microsoft.Xrm.Sdk.Metadata.EntityFilters.Entity; using (_serviceProxy = GetCRMConnection()) { try { RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest { EntityFilters = filter, LogicalName = entitytype.LogicalName.ToLower() }; RetrieveEntityResponse retrieveEntityResponse = (RetrieveEntityResponse)_serviceProxy.Execute(retrieveEntityRequest); EntityMetadata entityMetadata = retrieveEntityResponse.EntityMetadata; entitytype.DisplayName = entityMetadata.DisplayName.UserLocalizedLabel != null?entityMetadata.DisplayName.UserLocalizedLabel.Label.ToString() : entityMetadata.LogicalName; entitytype.ObjectTypeCode = entityMetadata.ObjectTypeCode.Value; entitytype.LogicalName = entityMetadata.LogicalName; entitytype.PrimaryIdAttribute = entityMetadata.PrimaryIdAttribute; entitytype.PrimaryNameAttribute = entityMetadata.PrimaryNameAttribute; entitytype.IsCustomEntity = entityMetadata.IsCustomEntity.Value; entitytype.Attributes = new List <CRMAttribute>(); List <CRMAttribute> Attributes = new List <CRMAttribute>(); if (entitytype.IncludeAttributes) { foreach (AttributeMetadata metadata in entityMetadata.Attributes) { CRMAttribute attrib = new CRMAttribute(); attrib.AttributeType = metadata.AttributeType.HasValue ? metadata.AttributeType.Value.ToString() : ""; attrib.Description = metadata.Description.UserLocalizedLabel != null ? metadata.Description.UserLocalizedLabel.Label : ""; attrib.DisplayName = metadata.DisplayName.UserLocalizedLabel != null ? metadata.DisplayName.UserLocalizedLabel.Label : metadata.LogicalName; attrib.IsPrimaryId = metadata.IsPrimaryId.HasValue ? metadata.IsPrimaryId.Value : false; attrib.IsPrimaryName = metadata.IsPrimaryName.HasValue ? metadata.IsPrimaryName.Value : false; attrib.IsValidForCreate = metadata.IsValidForCreate.HasValue ? metadata.IsValidForCreate.Value : false; attrib.IsValidForRead = metadata.IsValidForRead.HasValue ? metadata.IsValidForRead.Value : false; attrib.IsValidForUpdate = metadata.IsValidForUpdate.HasValue ? metadata.IsValidForUpdate.Value : false; attrib.LogicalName = metadata.LogicalName; attrib.RequiredLevel = metadata.RequiredLevel.Value.ToString(); attrib.SchemaName = metadata.SchemaName; Attributes.Add(attrib); } entitytype.Attributes = Attributes; } } catch (Exception ex) { throw; } } return(entitytype); }
public CRMEntityList CRMGetAllEntities(CRMEntityList EntityList) { OrganizationServiceProxy _serviceProxy; List <CRMEntityMetadata> Results = new List <CRMEntityMetadata>(); using (_serviceProxy = GetCRMConnection()) { try { RetrieveAllEntitiesRequest retrieveAllEntitiesRequest = new RetrieveAllEntitiesRequest { EntityFilters = EntityFilters.Entity, }; RetrieveAllEntitiesResponse retrieveAllEntitiesResponse = (RetrieveAllEntitiesResponse)_serviceProxy.Execute(retrieveAllEntitiesRequest); foreach (EntityMetadata Metadata in retrieveAllEntitiesResponse.EntityMetadata) { try { CRMEntityMetadata Entity = new CRMEntityMetadata(); Entity.DisplayName = Metadata.DisplayName.UserLocalizedLabel != null?Metadata.DisplayName.UserLocalizedLabel.Label.ToString() : Metadata.LogicalName; Entity.ObjectTypeCode = Metadata.ObjectTypeCode.HasValue ? Metadata.ObjectTypeCode.Value : 0; Entity.LogicalName = Metadata.LogicalName; Entity.PrimaryIdAttribute = Metadata.PrimaryIdAttribute; Entity.PrimaryNameAttribute = Metadata.PrimaryNameAttribute; Entity.IsCustomEntity = Metadata.IsCustomEntity.HasValue ? Metadata.IsCustomEntity.Value : false; Entity.Attributes = new List <CRMAttribute>(); Results.Add(Entity); } catch (Exception e) { throw; } } //EntityList.Entities = new List<CRMEntityMetadata>(); EntityList.Entities = Results; } catch (Exception ex) { throw; } } return(EntityList); }
public CRMEntityMetadata CRMGetEntityMetadata(CRMEntityMetadata crmEntityMetadata) { CRMFunctions function = new CRMFunctions(crmEntityMetadata.Config); return function.CRMGetEntityMetadata(crmEntityMetadata); }
private void btnGetAttributes_Click(object sender, RoutedEventArgs e) { CRMEntityMetadata emd = cbEntities.SelectedItem as CRMEntityMetadata; CRMEntityMetadata md = new CRMEntityMetadata(); md.LogicalName = emd.LogicalName; md.IncludeAttributes = true; cbAttributes.ItemsSource = functions.CRMGetEntityMetadata(md).Attributes.Where(p => p.AttributeType == "Picklist"); }
public CRMEntityList CRMGetAllEntities(CRMEntityList EntityList) { OrganizationServiceProxy _serviceProxy; List<CRMEntityMetadata> Results = new List<CRMEntityMetadata>(); using (_serviceProxy = GetCRMConnection()) { try { RetrieveAllEntitiesRequest retrieveAllEntitiesRequest = new RetrieveAllEntitiesRequest { EntityFilters = EntityFilters.Entity, }; RetrieveAllEntitiesResponse retrieveAllEntitiesResponse = (RetrieveAllEntitiesResponse)_serviceProxy.Execute(retrieveAllEntitiesRequest); foreach (EntityMetadata Metadata in retrieveAllEntitiesResponse.EntityMetadata) { try { CRMEntityMetadata Entity = new CRMEntityMetadata(); Entity.DisplayName = Metadata.DisplayName.UserLocalizedLabel != null ? Metadata.DisplayName.UserLocalizedLabel.Label.ToString() : Metadata.LogicalName; Entity.ObjectTypeCode = Metadata.ObjectTypeCode.HasValue ? Metadata.ObjectTypeCode.Value : 0; Entity.LogicalName = Metadata.LogicalName; Entity.PrimaryIdAttribute = Metadata.PrimaryIdAttribute; Entity.PrimaryNameAttribute = Metadata.PrimaryNameAttribute; Entity.IsCustomEntity = Metadata.IsCustomEntity.HasValue ? Metadata.IsCustomEntity.Value : false; Entity.Attributes = new List<CRMAttribute>(); Results.Add(Entity); } catch (Exception e) { throw; } } //EntityList.Entities = new List<CRMEntityMetadata>(); EntityList.Entities = Results; } catch (Exception ex) { throw; } } return EntityList; }
public CRMEntityMetadata CRMGetEntityMetadata(CRMEntityMetadata entitytype) { OrganizationServiceProxy _serviceProxy; Microsoft.Xrm.Sdk.Metadata.EntityFilters filter = entitytype.IncludeAttributes ? Microsoft.Xrm.Sdk.Metadata.EntityFilters.Attributes : Microsoft.Xrm.Sdk.Metadata.EntityFilters.Entity; using (_serviceProxy = GetCRMConnection()) { try { RetrieveEntityRequest retrieveEntityRequest = new RetrieveEntityRequest { EntityFilters = filter, LogicalName = entitytype.LogicalName.ToLower() }; RetrieveEntityResponse retrieveEntityResponse = (RetrieveEntityResponse)_serviceProxy.Execute(retrieveEntityRequest); EntityMetadata entityMetadata = retrieveEntityResponse.EntityMetadata; entitytype.DisplayName = entityMetadata.DisplayName.UserLocalizedLabel != null ? entityMetadata.DisplayName.UserLocalizedLabel.Label.ToString() : entityMetadata.LogicalName; entitytype.ObjectTypeCode = entityMetadata.ObjectTypeCode.Value; entitytype.LogicalName = entityMetadata.LogicalName; entitytype.PrimaryIdAttribute = entityMetadata.PrimaryIdAttribute; entitytype.PrimaryNameAttribute = entityMetadata.PrimaryNameAttribute; entitytype.IsCustomEntity = entityMetadata.IsCustomEntity.Value; entitytype.Attributes = new List<CRMAttribute>(); List<CRMAttribute> Attributes = new List<CRMAttribute>(); if (entitytype.IncludeAttributes) { foreach (AttributeMetadata metadata in entityMetadata.Attributes) { CRMAttribute attrib = new CRMAttribute(); attrib.AttributeType = metadata.AttributeType.HasValue ? metadata.AttributeType.Value.ToString() : ""; attrib.Description = metadata.Description.UserLocalizedLabel != null ? metadata.Description.UserLocalizedLabel.Label : ""; attrib.DisplayName = metadata.DisplayName.UserLocalizedLabel != null ? metadata.DisplayName.UserLocalizedLabel.Label : metadata.LogicalName; attrib.IsPrimaryId = metadata.IsPrimaryId.HasValue ? metadata.IsPrimaryId.Value : false; attrib.IsPrimaryName = metadata.IsPrimaryName.HasValue ? metadata.IsPrimaryName.Value : false; attrib.IsValidForCreate = metadata.IsValidForCreate.HasValue ? metadata.IsValidForCreate.Value : false; attrib.IsValidForRead = metadata.IsValidForRead.HasValue ? metadata.IsValidForRead.Value : false; attrib.IsValidForUpdate = metadata.IsValidForUpdate.HasValue ? metadata.IsValidForUpdate.Value : false; attrib.LogicalName = metadata.LogicalName; attrib.RequiredLevel = metadata.RequiredLevel.Value.ToString(); attrib.SchemaName = metadata.SchemaName; Attributes.Add(attrib); } entitytype.Attributes = Attributes; } } catch (Exception ex) { throw; } } return entitytype; }
private Property SetEntityMetadataProperties(Property prop, CRMEntityMetadata task) { if (task != null) { switch (prop.Name.ToLower()) { case "entitylogicalname": prop.Value = task.LogicalName; break; case "entitydisplayname": prop.Value = task.DisplayName; break; case "entityobjecttypecode": prop.Value = task.ObjectTypeCode; break; case "entityprimaryidattribute": prop.Value = task.PrimaryIdAttribute; break; case "entityprimarynameattribute": prop.Value = task.PrimaryNameAttribute; break; case "entityiscustomentity": prop.Value = task.IsCustomEntity; break; } } return prop; }
private void GetEntityAttributes(ref ServiceObject so) { SourceCode.SmartObjects.Services.ServiceSDK.Objects.Method meth = so.Methods[0]; CRMEntityMetadata entitymetadata = new CRMEntityMetadata(); entitymetadata.Config = crmconfig; try { entitymetadata.LogicalName = NotNull(so.Properties["EntityLogicalName"].Value); entitymetadata.IncludeAttributes = true; CRMEntityMetadata response = CRMFunctions.CRMGetEntityMetadata(entitymetadata); so.Properties.InitResultTable(); foreach (CRMAttribute ret in response.Attributes) { for (int c = 0; c < meth.ReturnProperties.Count; c += 1) { Property prop = so.Properties[meth.ReturnProperties[c]]; prop = SetGetEntityAttributeProperties(prop, ret); } so.Properties.BindPropertiesToResultTable(); } } catch (Exception ex) { throw; } }