public bool QueryAttributeDisplayNamesForTwoEntities() { MetadataQueryBuilder builder = new MetadataQueryBuilder(); builder.AddEntities(new List <string>("account", "contact"), new List <string>("Attributes", "DisplayName", "DisplayCollectionName")); builder.AddAttributes(new List <string>("name", "firstname", "statecode", "statuscode"), new List <string>("DisplayName")); RetrieveMetadataChangesResponse response = (RetrieveMetadataChangesResponse)OrganizationServiceProxy.Execute(builder.Request); return(true); }
public void QueryMetadata() { // Load the display Names MetadataQueryBuilder builder = new MetadataQueryBuilder(); List <string> entities = new List <string>(); List <string> attributes = new List <string>(); foreach (string entityLogicalName in EntityLookup.Keys) { entities.Add(entityLogicalName); EntityQuery entity = EntityLookup[entityLogicalName]; foreach (string attributeLogicalName in entity.Attributes.Keys) { AttributeQuery attribute = entity.Attributes[attributeLogicalName]; string fieldName = attribute.LogicalName; int pos = fieldName.IndexOf('.'); if (entity.AliasName != null && pos > -1) { fieldName = fieldName.Substr(pos); } attributes.Add(fieldName); } } builder.AddEntities(entities, new List <string>("Attributes", "DisplayName", "DisplayCollectionName", "PrimaryImageAttribute")); builder.AddAttributes(attributes, new List <string>("DisplayName", "AttributeType", "IsPrimaryName")); builder.SetLanguage((int)Script.Literal("USER_LANGUAGE_CODE")); RetrieveMetadataChangesResponse response = (RetrieveMetadataChangesResponse)OrganizationServiceProxy.Execute(builder.Request); // Update the display names // TODO: Add the lookup relationship in brackets for alias entitie foreach (EntityMetadata entityMetadata in response.EntityMetadata) { // Get the entity EntityQuery entityQuery = EntityLookup[entityMetadata.LogicalName]; entityQuery.DisplayName = entityMetadata.DisplayName.UserLocalizedLabel.Label; entityQuery.DisplayCollectionName = entityMetadata.DisplayCollectionName.UserLocalizedLabel.Label; entityQuery.PrimaryImageAttribute = entityMetadata.PrimaryImageAttribute; entityQuery.EntityTypeCode = entityMetadata.ObjectTypeCode; foreach (AttributeMetadata attribute in entityMetadata.Attributes) { if (entityQuery.Attributes.ContainsKey(attribute.LogicalName)) { // Set the type AttributeQuery attributeQuery = entityQuery.Attributes[attribute.LogicalName]; attributeQuery.AttributeType = attribute.AttributeType; switch (attribute.AttributeType) { case AttributeTypeCode.Lookup: case AttributeTypeCode.Picklist: case AttributeTypeCode.Customer: case AttributeTypeCode.Owner: case AttributeTypeCode.Status: case AttributeTypeCode.State: case AttributeTypeCode.Boolean_: LookupAttributes[attribute.LogicalName] = attributeQuery; break; } attributeQuery.IsPrimaryName = attribute.IsPrimaryName; // If the type is a lookup, then add the 'name' on to the end in the fetchxml // this is so that we search the text value and not the numeric/guid value foreach (Column col in attributeQuery.Columns) { col.Name = attribute.DisplayName.UserLocalizedLabel.Label; col.DataType = attribute.IsPrimaryName.Value ? "PrimaryNameLookup" : attribute.AttributeType.ToString(); } } } } }