在 CRM 2016 中使用 addCustomView 时出错
Error using addCustomView in CRM 2016
CRM 中有两个实体,'Contacts' 和一个名为 'Services' 的自定义实体,它们以多对多关系连接。在单独的表单中,实体 'Service Activity' 中有一个 服务字段 和一个 联系人字段 。我的目标是使用所选服务过滤 联系人字段 ,但前提是 服务字段 已填充。如果已填充,我想向 联系人字段 添加自定义视图,该视图仅显示连接到指定服务记录的联系人。否则,联系人字段 仅显示默认视图。
这是我的代码:
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);
}
}
我使用已保存的查询从我创建的自定义视图中检索了 fetchXml 和 layoutXml。在视图中,我过滤了一个特定的服务记录以测试它是否会 return 正确的联系人记录,它确实这样做了,但在我的代码中我用从中检索到的名称和 ID 替换了特定的服务名称和 ID在表单的 服务字段 中指定的记录。
当服务字段为空时,联系人字段设置为默认视图。但是,如果 服务字段 已填充,则在您尝试选择联系人记录时,表单 return 会出错。错误是不提供任何信息的一般性 "An error has occurred" 错误,这无济于事。
是我的代码不正确还是我的目标无法实现?
这就是您的抓取应该如何工作
<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'
和"<attribute name='contactid' />"
是重复的
CRM 中有两个实体,'Contacts' 和一个名为 'Services' 的自定义实体,它们以多对多关系连接。在单独的表单中,实体 'Service Activity' 中有一个 服务字段 和一个 联系人字段 。我的目标是使用所选服务过滤 联系人字段 ,但前提是 服务字段 已填充。如果已填充,我想向 联系人字段 添加自定义视图,该视图仅显示连接到指定服务记录的联系人。否则,联系人字段 仅显示默认视图。
这是我的代码:
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);
}
}
我使用已保存的查询从我创建的自定义视图中检索了 fetchXml 和 layoutXml。在视图中,我过滤了一个特定的服务记录以测试它是否会 return 正确的联系人记录,它确实这样做了,但在我的代码中我用从中检索到的名称和 ID 替换了特定的服务名称和 ID在表单的 服务字段 中指定的记录。
当服务字段为空时,联系人字段设置为默认视图。但是,如果 服务字段 已填充,则在您尝试选择联系人记录时,表单 return 会出错。错误是不提供任何信息的一般性 "An error has occurred" 错误,这无济于事。
是我的代码不正确还是我的目标无法实现?
这就是您的抓取应该如何工作
<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'
和"<attribute name='contactid' />"
是重复的