简体   繁体   English

crm 4.0过滤的查找

[英]crm 4.0 filtered lookup

I have a lookup field in my base-entity. 我的基本实体中有一个查找字段。 The target entity has a number-field in it. 目标实体中有一个数字字段。

When I open the lookup-dialog all the target-records are shown, but I only want to show the records where the number-field is 123, for example. 当我打开查找对话框时,将显示所有目标记录,但是我只想显示数字字段为123的记录。

the value is fixed, but how can I filter the lookupfield. 该值是固定的,但如何过滤lookupfield。 Best would be, if I could edit the fetchxml in javascript, but I don't know how... 最好的办法是,如果我可以用javascript编辑fetchxml,但是我不知道如何...

只有两个选项: 非常不受支持的修改插件 (我从未使用过插件,所以我无法确定它是否受支持)。

Unfortunately I don't believe there is a perfect way to do it. 不幸的是,我不认为有完美的方法。 Is upgrading to CRM 2011 an option? 是否可以选择升级到CRM 2011? In 2011 it is quite easy to filter a lookup. 在2011年,过滤查找非常容易。 The following sample shows how to filter one lookup based on another. 下面的示例演示如何基于一个查找来过滤一个查找。

function filterSecondLookup()
{
    try {
        var lookupObject = Xrm.Page.getAttribute("lookup_one").getValue();

        if (lookupObject != null)
        {

            lookup_one_name = $('<span>').text(lookupObject[0].name).html();  // text of lookup
            lookup_one_id = lookupObject[0].id; // Guid of lookup

            var viewId = '{1ACB2B35-B07C-44D1-868D-258DEEAB88E2}'; //Random GUID
            var entityName = 'account';
            var viewDisplayName = 'Filtered Lookup Name';

            var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                              "<entity name='account'>" +
                                "<attribute name='name' />" +
                                "<attribute name='address2_stateorprovince' />" +
                                "<attribute name='address2_line1' />" +
                                "<attribute name='address2_city' />" +
                                "<attribute name='accountid' />" +
                                "<order attribute='name' descending='false' />" +
                                "<link-entity name='lookup_one' from='lookup_one_id' to='lookup_one_id' alias='aa'>" +
                                  "<filter type='and'>" +
                                    "<condition attribute='lookup_one_id' operator='eq' uiname='" + lookup_one_name + "' uitype='lookup_one_id' value='" + lookup_one_id + "' />" +
                                  "</filter>" +
                                "</link-entity>" +
                              "</entity>" +
                            "</fetch>";

            var layoutXml = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
                          "<row name='result' id='accountid'>" +
                            "<cell name='name' width='200' />" +
                            "<cell name='address2_line1' width='150' />" +
                            "<cell name='address2_city' width='150' />" +
                            "<cell name='address2_stateorprovince' width='150' />" +
                          "</row>" +
                        "</grid>";

            Xrm.Page.getControl('lookup_two').addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
        }
        else
        {
            Xrm.Page.getControl("lookup_two").setDefaultView(window.defaultSiteViewId );
        }
    }
    catch (ex)
    {
        alert("Error in filterSecondLookup: " + ex);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM