CRM中有两个实体,'联系人'以及一个名为' Services'的自定义实体,它与多对多关系相关联。在单独的表单中,在实体“服务活动”中,有一个服务字段和一个联系人字段。我的目标是使用所选服务过滤联系人字段,但前提是填充了服务字段。如果已填充,我想将自定义视图添加到联系人字段,该视图仅显示连接到指定服务记录的联系人。否则,联系人字段仅显示默认视图。
这是我的代码:
function filtroRecurso()
{
var servicioEd = Xrm.Page.data.entity.attributes.get("new_servicio");
if (servicioEd.getValue() != null)
{
var serviceId = servicioEd.getValue()[0].id;
var serviceName = servicioEd.getValue()[0].name;
var viewId = "{00000000-0000-0000-0000-000000000001}";
var entityName = "contact";
var viewDisplayName = "Custom View";
var fetchXml;
fetchXml = "<fetchxml>" +
"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
"<entity name='contact'>" +
"<attribute name='fullname' />" +
"<attribute name='new_contacttype' />" +
"<attribute name='telephone1' />" +
"<attribute name='new_prepacademico' />" +
"<attribute name='new_municipio' />" +
"<attribute name='new_modalidades' />" +
"<attribute name='emailaddress1' />" +
"<attribute name='address1_line2' />" +
"<attribute name='address1_line1' />" +
"<attribute name='contactid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='statecode' operator='eq' value='0' />" +
"<condition attribute='new_contacttype' operator='eq' value='100000019' />" +
"</filter>" +
"<link-entity name='connection' from='record1id' to='contactid' alias='ab'>" +
"<filter type='and'>" +
"<condition attribute='record2id' operator='eq' value='" + serviceId + "' />" +
"</filter>" +
"</link-entity>" +
"</entity>" +
"</fetch>" +
"</fetchxml>";
var layoutXml = "<layoutxml>" +
"<grid name='resultset' object='2' jump='fullname' select='1' preview='1' icon='1'>" +
"<row name='result' id='contactid'>" +
"<cell name='fullname' width='150' />" +
"<cell name='new_contacttype' width='100' />" +
"<cell name='new_prepacademico' width='100' />" +
"<cell name='new_modalidades' width='100' />" +
"<cell name='telephone1' width='100' />" +
"<cell name='emailaddress1' width='150' />" +
"<cell name='address1_line1' width='150' />" +
"<cell name='address1_line2' width='150' />" +
"<cell name='new_municipio' width='100' />" +
"</row>" +
"</grid>" +
"</layoutxml>";
Xrm.Page.getControl("new_maestros").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
}
}
我使用我创建的自定义视图中的Saved Queries检索了fetchXml和layoutXml。在视图中,我按特定的服务记录进行过滤,以测试它是否会返回正确的联系人记录,但在我的代码中,我将特定的服务名称和id替换为从记录中指定的记录中检索的名称和ID。表单上的服务字段。
当服务字段为空时,联系人字段将设置为其默认视图。但是,如果填充了服务字段,则当您尝试选择联系人记录时,表单会返回错误。它没有帮助,错误是通用的&#34;发生错误&#34;一个没有提供信息。
我的代码不正确还是我的目标无法实现?
答案 0 :(得分:1)
这是你的提取应该如何工作
isUserInteractionEnabled = false
我们删除<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
<entity name='contact'>
<attribute name='fullname' />
<attribute name='new_contacttype' />
<attribute name='telephone1' />
<attribute name='new_prepacademico' />
<attribute name='new_municipio' />
<attribute name='new_modalidades' />
<attribute name='emailaddress1' />
<attribute name='address1_line2' />
<attribute name='address1_line1' />
<attribute name='contactid' />
<order attribute='fullname' descending='false' />
<filter type='and'>
<condition attribute='statecode' operator='eq' value='0' />
<condition attribute='new_contacttype' operator='eq' value='100000019' />
</filter>
<link-entity name='connection' from='record1id' to='contactid' alias='ab'>
<filter type='and'>
<condition attribute='record2id' operator='eq' value='YourGUID' />
</filter>
</link-entity>
</entity>
</fetch>
和<fetchxml>
,比较</fetchxml>
和uiname='" + serviceName + "' uitype='new_services'
重复