![](/img/trans.png)
[英]C# Plugin For CRM2013 - Not receiving Product Name + Quantity in fetch xml query
[英]CRM 2013 C# PlugIn - Fetch XML Query
我的實體頁面上有一個網格訂單,用戶可以將產品添加到實體網格
對於我的插件,我需要知道哪些產品已插入到網格中,以便隨后可以生成CSV文件
我嘗試使用FetchXML查詢來檢索數據,如下所示;
string fetchxml = @"
<fetch mapping= 'logical'>
<entity name ='product'>
<attribute name = 'name'/>
</entity>
</fetch> ";
EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetchxml));foreach(var c in result.Entities){
if (result != null && result.Entities.Count > 0)
{
List<string> _product = new List<string>();
foreach (Entity _entity in result.Entities)
{
_product.Add(_entity.Attributes["name"].ToString());
}
string CSVFile = string.Join(",", _product.ToArray());string AddressPath = "FM-OR" + "_";
string AddressSavePath = @"\\fm\CRMdata\maesteg\" + AddressPath + ".csv";
System.IO.File.WriteAllText(AddressSavePath, CSVFile.ToString());
}
}
該代碼確實生成了我需要的所需CSV文件,但是它選擇了實體產品中的每條記錄,而不是網格中的所有記錄。 關於如何解決此問題有什么建議嗎?
謝謝,肖恩
您需要在提取查詢中使用Link-Entity和Filter。 檢查以下示例:
提取Xml應該是這樣的:
Guid orderId = (Guid)((Entity)context.InputParameters["Target"]).Id;
<?xml version="1.0"?>
<fetch distinct="true" mapping="logical" output-format="xml-platform" version="1.0">
<entity name="product">
<attribute name="name"/>
<attribute name="productnumber"/>
<attribute name="subjectid"/>
<attribute name="statecode"/>
<attribute name="productid"/>
<order descending="false" attribute="productnumber"/>
<link-entity name="salesorderdetail" alias="aa" to="productid" from="productid">
<link-entity name="salesorder" alias="ab" to="salesorderid" from="salesorderid">
<filter type="and">
<condition attribute="salesorderid" operator="eq" value=orderId />
</filter>
</link-entity>
</link-entity>
</entity>
</fetch>
“達到某個值”是觸發插件的實體的ID,請檢查以下鏈接: http : //msdn.microsoft.com/zh-cn/library/gg309673.aspx
您的代碼應如下所示:
@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
<entity name='product'>
<attribute name = 'name'/>
<order attribute='name' descending='false' />
<filter type='and'>
<condition attribute='productid' operator='eq' value=" + context.InputParameters["Target"].id + @" />
</filter>
<link-entity name='order' from='projectid' to='project' alias='Order'>
........
</link-entity>
</entity>
</fetch>"
請記住,我執行的字符串連接可能是錯誤的,但是我必須這樣做,以突出顯示語法:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.