c# - 如何在链接实体上使用过滤器?
问题描述
我正在使用 crm 2016 并尝试根据链接性过滤获取产品(自定义实体)记录,我需要获取所有具有 Active productstatus 的产品并且链接的电话类别为:fun
not open
产品 - (productstatus = Active) & (linkedphonecallcategory = fun && linkedphonecallstatus != open)
当我运行当前查询时,我得到的结果没有链接实体过滤器。我不明白为什么。
这是我的代码:
FilterExpression filter1 = new FilterExpression(LogicalOperator.And);
filter1.Conditions.Add(new ConditionExpression("phonecallcategory", ConditionOperator.Equal, "fun"));
filter1.Conditions.Add(new ConditionExpression("statecode", ConditionOperator.NotEqual, 0));
LinkEntity phoneCallLink = new LinkEntity("product", "phonecall", "productid", "regardingobjectid", JoinOperator.LeftOuter);
phoneCallLink.LinkCriteria = filter1;
phoneCallLink.EntityAlias = "products";
QueryExpression query = new QueryExpression("product");
query.ColumnSet = new ColumnSet("productname");
query.LinkEntities.Add(phoneCallLink);
query.Criteria.AddCondition(new ConditionExpression("productstatus", ConditionOperator.Equal, 0));
EntityCollection AllProductsWithSpecificCallsNotOpen = new EntityCollection();
解决方案
你可以看看这里,我已经重组了你的查询,使其易于理解
示例:带有 LinkEntity 的 QueryExpression
//Link
LinkEntity phoneCallLink = new LinkEntity();
phoneCallLink.LinkFromEntityName = "new_product";
phoneCallLink.LinkToEntityName = "phonecall";
phoneCallLink.LinkFromAttributeName = "new_productid";
phoneCallLink.LinkToAttributeName = "regardingobjectid";
phoneCallLink.JoinOperator = JoinOperator.LeftOuter;
phoneCallLink.EntityAlias = "phone";
phoneCallLink.LinkCriteria.Conditions.Add(new ConditionExpression("statecode", ConditionOperator.NotEqual, 0));
phoneCallLink.LinkCriteria.Conditions.Add(new ConditionExpression("phonecallcategory", ConditionOperator.Equal, "fun"));
//Query
QueryExpression query = new QueryExpression("new_product");
query.ColumnSet = new ColumnSet("new_name");
query.LinkEntities.Add(phoneCallLink);
query.Criteria.AddCondition(new ConditionExpression("statecode", ConditionOperator.Equal, 0));
//Execute
var AllProductsWithSpecificCallsNotOpen = service.RetrieveMultiple(query);
如果这仍然不起作用,您可以构建和导出fetchXml
查询并将其转换为查询表达式:
示例:将 FetchXml 转换为 QueryExprssion
string fetchXml =
@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='account'>
<attribute name='name' />
<attribute name='accountid' />
<order attribute='createdon' descending='true' />
<order attribute='modifiedon' descending='true' />
<filter type='and'>
<condition attribute='createdon' operator='this-month' />
</filter>
</entity>
</fetch>";
// Convert the FetchXML into a query expression.
var conversionRequest = new FetchXmlToQueryExpressionRequest();
conversionRequest.FetchXml = fetchXml; //fetchXml string
var conversionResponse =(FetchXmlToQueryExpressionResponse)service.Execute(conversionRequest);
var result = conversionResponse.Results.FirstOrDefault();
推荐阅读
- codenameone - 当应用程序处于后台时,BackgroundLocationListener 不调用 Rest API
- python - 从参数字典生成边界
- r - str_replace_all 只获得第一
- python - Python 单词搜索(最简单)
- git - 有没有办法在 CLI 中显示 Github 网络图?
- batch-file - 使用具有特殊字符的文本设置变量
- jenkins - 如何在一份 Jenkins 工作中发布多个 Fitnesse 结果报告?
- php - 在php中转换数组结构
- r - R apply() 字符类型的奇怪行为
- r - 将带有 geom_seg 的线条添加到 R 中的堆叠条形图