[英]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.