0

CRM 中有两个实体,“联系人”和一个名为“服务”的自定义实体,它们以多对多关系连接。在单独的表单中,在实体“服务活动”中,有一个服务字段和一个联系人字段。我的目标是使用所选服务过滤联系人字段,但前提是填充了服务字段。如果已填充,我想向联系人字段添加一个自定义视图,该字段仅显示连接到指定服务记录的联系人。否则,联系人字段仅显示默认视图。

这是我的代码:

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表单上的服务字段。

服务字段为空时,联系人字段设置为其默认视图。但是,如果填充了服务字段,当您尝试选择联系人记录时,表单会返回错误。错误是没有提供任何信息的通用“发生错误”并没有帮助。

我的代码不正确还是我的目标无法实现?

4

1 回答 1

1

这就是您的 fetch 应该如何工作

<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>and </fetchxml>,比较uiname='" + serviceName + "' uitype='new_services'and "<attribute name='contactid' />"是重复的

于 2017-01-13T15:00:12.203 回答