- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 CRM 之外有一个网页,允许用户执行 CRM 查找。我需要像在普通 CRM UI 中一样使用快速搜索来过滤查找结果。
我获取所选实体/ View 的 FetchXML,然后获取所选实体的快速搜索 View 的 FetchXML,提取 isquickfindfields=1 的过滤器节点,将 {0} 替换为他们在搜索框中键入的内容,插入将修改后的节点放入选中 View 的FetchXML中,并执行。
我遇到的问题是一些快速搜索过滤器针对相关实体的 ID 字段,但匹配需要针对该实体的主要名称属性。
例如,这里是对帐户实体的快速搜索:
<fetch version="1.0" output-format="xml-platform" mapping="logical">
<entity name="account">
<attribute name="name" />
<attribute name="primarycontactid" />
<attribute name="address1_city" />
<attribute name="telephone1" />
<attribute name="emailaddress1" />
<order attribute="name" descending="false" />
<filter type="and">
<condition attribute="statecode" operator="eq" value="0" />
</filter>
<filter type="or" isquickfindfields="1">
<condition attribute="primarycontactid" operator="like" value="{0}" />
<condition attribute="telephone1" operator="like" value="{0}" />
<condition attribute="emailaddress1" operator="like" value="{0}" />
<condition attribute="accountnumber" operator="like" value="{0}" />
<condition attribute="name" operator="like" value="{0}" />
</filter>
<attribute name="accountid" />
</entity>
当我插入搜索文本并执行 View 时,我从 RetrieveMultiple 得到了这个错误:
An exception System.FormatException was thrown while trying to convert input value '%acme%' to attribute 'account.primarycontactid'. Expected type of attribute value: System.Guid. Exception raised: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
如果我使用普通的 CRM 界面,对帐户进行查找并在快速搜索框中输入联系人姓名,搜索将按预期进行(列出帐户,其中主要联系人的姓名是我输入的)。因此,我假设当 CRM 查询数据库时,它会“智能地”将非 Guid 字符串与实体引用的主要名称属性相匹配。
这是添加快速搜索过滤器的代码块(整个方法的 pastebin):
if (string.IsNullOrWhiteSpace(searchString) == false)
{
var quickSearch = CRMCache.SavedQueries.FirstOrDefault(q => q.ReturnedTypeCode == view.ReturnedTypeCode && q.QueryType == SavedQueryQueryType.QuickFindSearch);
if (quickSearch != null)
{
var quickSearchXml = XElement.Parse(quickSearch.FetchXml);
var quickSearchFilter = quickSearchXml.XPathSelectElement("//filter[@isquickfindfields=1]");
foreach (var condition in quickSearchFilter.Elements("condition"))
{
condition.SetAttributeValue("value", string.Format(condition.Attribute("value").Value, "%" + searchString + "%"));
}
viewEntityNode.Add(quickSearchFilter);
}
}
虽然我很好奇普通 CRM 用户界面如何处理这个问题,但我的问题是如何在查找/ View 上动态应用快速搜索过滤,以正确过滤相关实体的主要名称属性?
[编辑澄清]
快速搜索(或快速查找)是 CRM 中的一种 View 类型。它定义了当用户在快速搜索框中输入文本或过滤查找时搜索哪些属性。所有实体都有一个快速搜索 View ,一个实体只能有一个。
匹配相关实体名称的要求来自快速搜索 View 。并非所有这些都包含对实体引用的筛选器,但是当它包含时,我需要匹配名称而不是 guid。由于正常的 CRM UI 正确地将搜索字符串应用于相关实体的名称,即使快速搜索 View 的 FetchXML 具有针对 id 的过滤器,我原以为 CRM 会在内部处理这种情况。显然,情况并非如此(我得到的错误表明了这一点)。所以我需要检测这种情况并做一些不同的事情,我想动态地做这件事。
动态地,我的意思是我的代码没有一堆预定义的 FetchXML 字符串;它没有针对特定实体、 View 或搜索要求进行编码;并且不需要每次添加或更改新实体或 View 时都对其进行修改。也许“动态”在这种情况下不是一个好词,但我不知道还能怎么调用它。实体/ View 不可知?
我不想要这样的代码:
SearchResults ExecuteView(string entityLogicalName, string searchString)
{
switch(entityLogicalName)
{
case "account":
return searchAccounts(searchString);
... all other enties ...
default:
throw new Exception("Unknown entity type: " + entityLogicalName);
}
}
SearchResults searchAccounts(searchString)
{
var fetchXml = string.Format(@"
<fetch>
<entity name=""account"">
<link-entity name=""contact"" from=""contactid"" to=""primarycontactid"">
<attribute name=""name"" alias=""name"" />
<filter type=""and"">
<condition attribute=""name"" operator=""like"" value=""%{0}%"" />
</filter>
</link-entity>
</entity>
</fetch>", searchString);
return executeSearch(fetchXml);
}
因为 CRM 中的更改(添加/删除实体、添加/删除/更新 View )需要更新代码以匹配。
最佳答案
我不知道 CRM 是如何使用字符串来搜索 guid 的,但我怀疑它会执行一些预处理或一些您可能无法使用的后端内容。 (我想如果你真的想知道你可以尝试反编译 CRM .dll,但这可能需要一段时间)。
因此,作为替代方案,我会建议您进一步操作 FetchXml 的处理阶段,如果您借助元数据服务执行此操作,您应该能够在没有任何硬编码的情况下逃脱。
因此,以获取帐户为例,我认为您需要编辑 xml,以便 id 属性附加 name
,例如主要联系人 ID 名称
。这是 FilteredView 中数据库列的名称,我相信它可以从 FetchXml 获得。 (如果这不起作用,请添加一个带有名称过滤器的 link-entity
并删除现有条件)。
所以你知道什么时候附加 name
我建议:
EntityReference
,则使用适当的条件更新快速查找 View 搜索。关于c# - CRM FetchXml,如何动态添加与相关实体名称匹配的快速搜索过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15389858/
我有一个程序可以将发票从我们的 CRM Dynamics Online 系统提取到一个 .csv 文件中。 有时我们的销售人员会在 CRM 中的同一个订单上创建多张发票,我需要一种方法来删除 .csv
我正在尝试在 FetchXML 中使用多个条件进行左外连接。 这是我要实现的大致 SQL: SELECT incident.*, externalCheck.* FROM incident LEFT
如何使用 FetchXml 进行左连接? 考虑一个简单的 SQL 查询,如下所示: select person.name, address.city from person left join add
我正在为帐户创建一个子网格,以按多个字段显示所有相关联系人。这是我试图设置的 fetch xml: 我使用 document.get
我正在使用 CRM 2013 Online。我想生成有关机会实体的报告,如下所示: CampaignCode Open Opportunity Count Won Opportunity Co
我在 CRM 之外有一个网页,允许用户执行 CRM 查找。我需要像在普通 CRM UI 中一样使用快速搜索来过滤查找结果。 我获取所选实体/ View 的 FetchXML,然后获取所选实体的快速搜索
我需要创建一个条形图来显示我们在过去 3 个月内创建的帐户数量。我尝试过使用过去 X 个月的查询/ View ,但正如我在 post 中所说的那样它只是没有按照我想要的方式工作。我做了一些搜索,发现了
我一直避免使用 fetchxml,因为我不确定调用 crmService.Fetch(fetchXml) 后处理结果数据的最佳方式。在一些情况下,我使用带有 LINQ 的 XDocument 从该数据
我正在尝试构建一个与以下 SQL 查询相同的 FetchXML 查询。基本上,如果约会的自定义属性“dev_ownercommunityid”等于机会的 ownerid 属性,则输出机会名称和链接约会
请注意,虽然这个问题是一个完全不同的问题,但它直接关系到 this question. 以下是为我的 SSRS 图表返回数据集的脚本:
我们发现 CRM 2011 的 Linq 严重损坏 - 它似乎在没有对其执行任何 QA 的情况下进入。提供程序损坏程度的指标是 .Where(x => x== "b") 之类的查询有效,但此 .Whe
是否可以在 View 中显示来自嵌套链接实体的字段? 我有 3 个实体:统计信息、帐户和地址。 统计信息查找帐户,帐户查找地址。 我想要统计 View 中所有这些实体的字段。 我已经尝试过这个并得到一
我有一些性能很慢的 SQL 报告,所以我们将它们全部转换为 FetchXML,但所有 SQL 报告都有可选的所有条件,如下所示: SELECT ... FROM ... WHERE (@opera
在 Dynamics CRM 2015 中,我使用 ExecuteFetch请求查询数据。我需要结果集 XML 作为响应。 在结果集中,每个货币字段中的格式化值在货币符号和金额之间显示一个问号: 12
我明白了用于连接,但你能帮我把下面的翻译成英文吗? *insert a bunch of attributes* 我明白了用于联接,但未指定联接类型,所以这让我失望。如果未指定连接类型,
使用此查询,我可以在线检索 Microsoft Dynamics CRM 中的审计记录 但这缺少有关操作中发生的事情的信息,更具体地说是 old value和 new val
我有一个 javascript 函数,它使用 fetchXML 将自定义 View 添加到控件。我的问题是根上的计数属性 节点不工作。我将它设置为 6,但它返回 26 条记录(所有记录),由提取定义。
我正在处理两个实体:约会和费用。我的目标是让新的费用记录在指定费用日期 onChange 时自动填充其某些字段。它触发一个查询,该查询应该返回具有相同日期和所属用户的记录。 这是我的代码: funct
我想要一个显示来自 3 个实体的属性的 View : 统计信息查找帐户,帐户查找地址。 View 是关于统计的,我想要所有 3 个实体的属性;这甚至可能吗? 问题出在 GridXML 上。 我想在 G
我们即将使用 fetchXML 将 CRM 报告转换为 CRM 在线报告 该报告基于 CRM 数据库和我的自定义数据库 是否可以将 fetchXML 结果转换为临时表,以便我可以将临时表与其他查询连接
我是一名优秀的程序员,十分优秀!