/// <summary> /// Query to get orders of a contact by its ID /// </summary> /// <param name="contactID"></param> /// <returns></returns> private string GetOrdersOfQuery(Guid contactID) { /* * <fetch version="1.0" mapping="logical"> * <entity name="salesorder"> * <attribute name="name" /> * <attribute name="description" /> * <attribute name="new_orderid" /> * <link-entity name="connection" from="record1id" to="salesorderid"> * <filter type="and"> * <condition attribute="record1objecttypecode" operator="eq" value="1088" /> * <condition attribute="record2objecttypecode" operator="eq" value="2" /> * </filter> * <link-entity name="connectionrole" from="connectionroleid" to="record2roleid"> * <attribute name="name" alias="role" /> * </link-entity> * <link-entity name="contact" from="contactid" to="record2id"> * <filter type="and"> * <condition attribute="contactid" operator="eq" value="12ed419f-5863-e611-80e3-c4346bc516e8" /> * </filter> * </link-entity> * </link-entity> * </entity> * </fetch> */ var xml = new FetchXML(ENTITY); FetchElement entity = xml.EntityElement; entity.AddField("name") .AddField("description") .AddField("new_orderid"); FetchElement linkedConnection = entity.AddLinkEntity("connection", "record1id", "salesorderid"); FetchElement connectionFilter = linkedConnection.AddFilter(); connectionFilter.AddCondition("record1objecttypecode", "eq", "1088") .AddCondition("record2objecttypecode", "eq", "2"); linkedConnection.AddLinkEntity("connectionrole", "connectionroleid", "record2roleid") .AddField("name", "role"); FetchElement linkedContact = linkedConnection.AddLinkEntity("contact", "contactid", "record2id"); FetchElement contactFilter = linkedContact.AddFilter(); contactFilter.AddCondition("contactid", "eq", contactID.ToString()); return(xml.ToQueryString()); }
// fetchXml version for getting ordered products private string GetOderDetails(Guid orderID) { var xml = new FetchXML(ENTITY); FetchElement entity = xml.EntityElement; entity.AddFilter() .AddCondition("salesorderid", "eq", orderID.ToString()); entity.AddLinkEntity("product", "productid", "productid").AddField("name", "product"); return(xml.ToQueryString()); }
/// <summary> /// Build a query to get a list of child accounts of an account defined by its name /// </summary> /// <param name="parent"></param> /// <returns>The result from Dynamics server as string</returns> private string ListChildAccountsQuery(string parent) { var xml = new FetchXML(ENTITY); FetchElement entity = xml.EntityElement; entity.AddField("name"); entity.AddField("accountid"); FetchElement linkedEntiry = entity.AddLinkEntity("account", "accountid", "parentaccountid"); FetchElement filter = linkedEntiry.AddFilter(); filter.AddCondition("name", "eq", value: parent); return(xml.ToQueryString()); }
/// <summary> /// A link-entity which can be added to the main order query to get names of ordered product /// </summary> /// <returns></returns> // Not tested used yet private FetchElement OrderLineQuery() { var attributes = new Dictionary <string, string> { { "name", "salesorderdetail" }, { "from", "salesorderid" }, { "to", "salesorderid" } }; FetchElement linkedOrderLine = new FetchElement("link-entity", attributes); linkedOrderLine.AddField("priceperunit") .AddField("quantity") .AddField("manualdiscountamount_base"); FetchElement linkedProduct = linkedOrderLine.AddLinkEntity("product", "productid", "productid"); linkedProduct.AddField("name", "product"); return(linkedOrderLine); }