private List <Column> ParseLayoutXml(EntityQuery rootEntity, string layoutXml) { jQueryObject layout = jQuery.FromHtml(layoutXml); jQueryObject cells = layout.Find("cell"); List <Column> columns = new List <Column>(); cells.Each(delegate(int index, Element element) { string cellName = element.GetAttribute("name").ToString(); string logicalName = cellName; EntityQuery entity; AttributeQuery attribute; // Is this an alias attribute? int pos = cellName.IndexOf('.'); if (pos > -1) { // Aliased entity string alias = cellName.Substr(0, pos); logicalName = cellName.Substr(pos + 1); entity = AliasEntityLookup[alias]; } else { // Root entity entity = rootEntity; } // Does the attribute allready exist? if (entity.Attributes.ContainsKey(logicalName)) { // Already exists attribute = entity.Attributes[logicalName]; } else { // New attribute = new AttributeQuery(); attribute.Columns = new List <Column>(); attribute.LogicalName = logicalName; entity.Attributes[attribute.LogicalName] = attribute; } // Add column object widthAttribute = element.GetAttribute("width"); if (widthAttribute != null) { int width = int.Parse(element.GetAttribute("width").ToString()); object disableSorting = element.GetAttribute("disableSorting"); Column col = GridDataViewBinder.NewColumn(attribute.LogicalName, attribute.LogicalName, width); // Display name get's queried later col.Sortable = !(disableSorting != null && disableSorting.ToString() == "1"); attribute.Columns.Add(col); columns.Add(col); } }); return(columns); }
private void ParseFetchXml(FetchQuerySettings querySettings) { jQueryObject fetchElement = querySettings.FetchXml; // Get the entities and link entities - only support 1 level deep jQueryObject entityElement = fetchElement.Find("entity"); string logicalName = entityElement.GetAttribute("name"); EntityQuery rootEntity; // Get query from cache or create new if (!EntityLookup.ContainsKey(logicalName)) { rootEntity = new EntityQuery(); rootEntity.LogicalName = logicalName; rootEntity.Attributes = new Dictionary <string, AttributeQuery>(); EntityLookup[rootEntity.LogicalName] = rootEntity; } else { rootEntity = EntityLookup[logicalName]; } // Get Linked Entities(1 deep) jQueryObject linkEntities = entityElement.Find("link-entity"); linkEntities.Each(delegate(int index, Element element) { EntityQuery link = new EntityQuery(); link.Attributes = new Dictionary <string, AttributeQuery>(); link.AliasName = element.GetAttribute("alias").ToString(); link.LogicalName = element.GetAttribute("name").ToString(); if (!EntityLookup.ContainsKey(link.LogicalName)) { EntityLookup[link.LogicalName] = link; } else { string alias = link.AliasName; link = EntityLookup[link.LogicalName]; link.AliasName = alias; } if (!AliasEntityLookup.ContainsKey(link.AliasName)) { AliasEntityLookup[link.AliasName] = link; } }); querySettings.RootEntity = rootEntity; }
private void QueryQuickSearchEntities() { OrganizationServiceProxy.RegisterExecuteMessageResponseType("ExecuteFetch", typeof(ExecuteFetchResponse)); // Get the entities defined in the correct order string fetchxml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='multientitysearchentities'> <attribute name='entityname' /> <order attribute='entityorder' descending='false' /> </entity> </fetch>"; // We have to use the deprecated ExecuteFetchRequest because you can't access the multientitysearchentities through RetrieveMultiple ExecuteFetchRequest request = new ExecuteFetchRequest(); request.FetchXml = fetchxml; ExecuteFetchResponse entityList = (ExecuteFetchResponse)OrganizationServiceProxy.Execute(request); jQueryObject entityListDOM = jQuery.FromHtml(entityList.FetchXmlResult); _entityTypeNames = new List <string>(); jQueryObject results = entityListDOM.First().Find("result"); results.Each(delegate(int index, Element element) { string entityName = XmlHelper.SelectSingleNodeValue((XmlNode)(object)element, "entityname"); _entityTypeNames.Add(entityName); }); MetadataQueryBuilder builder = new MetadataQueryBuilder(); builder.AddEntities(_entityTypeNames, new List <string>("ObjectTypeCode", "DisplayCollectionName")); builder.SetLanguage((int)Script.Literal("USER_LANGUAGE_CODE")); RetrieveMetadataChangesResponse response = (RetrieveMetadataChangesResponse)OrganizationServiceProxy.Execute(builder.Request); _entityMetadata = new Dictionary <string, EntityMetadata>(); foreach (EntityMetadata entity in response.EntityMetadata) { _entityMetadata[entity.LogicalName] = entity; } }
public static jQueryObject SetReadOnly(jQueryObject elements, bool isReadOnly) { elements.Each(delegate(int index, Element el) { jQueryObject elx = jQuery.FromElement(el); string type = elx.GetAttribute("type"); if (elx.Is("select") || (type == "radio") || (type == "checkbox")) { if (isReadOnly) { elx.AddClass("readonly").Attribute("disabled", "disabled"); } else { elx.RemoveClass("readonly").RemoveAttr("disabled"); } } else { if (isReadOnly) { elx.AddClass("readonly").Attribute("readonly", "readonly"); } else { elx.RemoveClass("readonly").RemoveAttr("readonly"); } } return(true); }); return(elements); }
public static jQueryObject SetReadOnly(jQueryObject elements, bool isReadOnly) { elements.Each(delegate (int index, Element el) { jQueryObject elx = jQuery.FromElement(el); string type = elx.GetAttribute("type"); if (elx.Is("select") || (type == "radio") || (type == "checkbox")) { if (isReadOnly) { elx.AddClass("readonly").Attribute("disabled", "disabled"); } else { elx.RemoveClass("readonly").RemoveAttr("disabled"); } } else { if (isReadOnly) elx.AddClass("readonly").Attribute("readonly", "readonly"); else elx.RemoveClass("readonly").RemoveAttr("readonly"); } return true; }); return elements; }
private void ParseFetchXml(FetchQuerySettings querySettings) { jQueryObject fetchElement = querySettings.FetchXml; // Get the entities and link entities - only support 1 level deep jQueryObject entityElement = fetchElement.Find("entity"); string logicalName = entityElement.GetAttribute("name"); EntityQuery rootEntity; // Get query from cache or create new if (!EntityLookup.ContainsKey(logicalName)) { rootEntity = new EntityQuery(); rootEntity.LogicalName = logicalName; rootEntity.Attributes = new Dictionary <string, AttributeQuery>(); EntityLookup[rootEntity.LogicalName] = rootEntity; } else { rootEntity = EntityLookup[logicalName]; } // Get Linked Entities(1 deep) jQueryObject linkEntities = entityElement.Find("link-entity"); linkEntities.Each(delegate(int index, Element element) { EntityQuery link = new EntityQuery(); link.Attributes = new Dictionary <string, AttributeQuery>(); link.AliasName = element.GetAttribute("alias").ToString(); link.LogicalName = element.GetAttribute("name").ToString(); link.Views = new Dictionary <string, FetchQuerySettings>(); if (!EntityLookup.ContainsKey(link.LogicalName)) { EntityLookup[link.LogicalName] = link; } else { string alias = link.AliasName; link = EntityLookup[link.LogicalName]; link.AliasName = alias; } if (!AliasEntityLookup.ContainsKey(link.AliasName)) { AliasEntityLookup[link.AliasName] = link; } }); querySettings.RootEntity = rootEntity; // Issue #35 - Add any lookup/picklist quick find fields that are not included in results attributes will cause a format execption // because we don't have the metadata - this means that 'name' is not appended to the attribute // Add the search string and adjust any lookup columns jQueryObject conditions = fetchElement.Find("filter[isquickfindfields='1']"); conditions.First().Children().Each(delegate(int index, Element element) { logicalName = element.GetAttribute("attribute").ToString(); jQueryObject e = jQuery.FromElement(element); jQueryObject p = e.Parents("link-entity"); if (!querySettings.RootEntity.Attributes.ContainsKey(logicalName)) { AttributeQuery attribute = new AttributeQuery(); attribute.LogicalName = logicalName; attribute.Columns = new List <Column>(); querySettings.RootEntity.Attributes[logicalName] = attribute; } }); }