Mscrm2011 为多对多Subgrid的AddExisting按钮添加自定义过滤视图

请看这篇文章,按照他一步一步做,并根据自己的要求做些修改就可以了。

MSCRM 2011: Filtered Lookup for "Add Existing..." Button of a CRM N:N View

以防万一不能访问,这里把步骤大致说一下:

1. 添加Javascript Webresource,不用添加到CRM的表内:

    function addExistingFromSubGridCustom(params) {  
      
        var relName = params.gridControl.getParameter("relName"),  
            roleOrd = params.gridControl.getParameter("roleOrd"),  
            viewId = "{00000000-0000-0000-0000-000000000001}"; // a dummy view ID  
          
        var customView = {  
            fetchXml: params.fetchXml,  
            id: viewId,   
            layoutXml: params.layoutXml,  
            name: "Filtered Lookup View",  
            recordType: params.gridTypeCode,  
            Type: 0  
        };  
      
        var lookupItems = LookupObjects(null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);  
        if (lookupItems && lookupItems.items.length > 0) {  
            AssociateObjects(crmFormSubmit.crmFormSubmitObjectType.value, crmFormSubmit.crmFormSubmitId.value, params.gridTypeCode, lookupItems, IsNull(roleOrd) || roleOrd == 2, "", relName);  
        }  
    }  
      
    function addExistingFromSubGridAccount(gridTypeCode, gridControl) {  
        addExistingFromSubGridCustom({  
            gridTypeCode: gridTypeCode,  
            gridControl: gridControl,  
            fetchXml: "<fetch version='1.0' " +  
                           "output-format='xml-platform' " +  
                           "mapping='logical'>" +  
                       "<entity name='account'>" +  
                       "<attribute name='name' />" +  
                       "<attribute name='address1_city' />" +  
                       "<order attribute='name' " +  
                               "descending='false' />" +  
                       "<filter type='and'>" +  
                           "<condition attribute='ownerid' " +  
                                       "operator='eq-userid' />" +  
                           "<condition attribute='statecode' " +  
                                       "operator='eq' " +  
                                       "value='0' />" +  
                       "</filter>" +  
                       "<attribute name='primarycontactid' />" +  
                       "<attribute name='telephone1' />" +  
                       "<attribute name='accountid' />" +  
                       "<link-entity alias='accountprimarycontactidcontactcontactid' " +  
                                       "name='contact' " +  
                                       "from='contactid' " +  
                                       "to='primarycontactid' " +  
                                       "link-type='outer' " +  
                                       "visible='false'>" +  
                           "<attribute name='emailaddress1' />" +  
                       "</link-entity>" +  
                       "</entity>" +  
                   "</fetch>",  
            layoutXml: "<grid name='resultset' " +  
                                 "object='1' " +  
                                 "jump='name' " +  
                                 "select='1' " +  
                                 "icon='1' " +  
                                 "preview='1'>" +  
                             "<row name='result' " +  
                                  "id='accountid'>" +  
                               "<cell name='name' " +  
                                     "width='300' />" +  
                               "<cell name='telephone1' " +  
                                     "width='100' />" +  
                               "<cell name='address1_city' " +  
                                     "width='100' />" +  
                               "<cell name='primarycontactid' " +  
                                     "width='150' />" +  
                               "<cell name='accountprimarycontactidcontactcontactid.emailaddress1' " +  
                                     "width='150' " +  
                                     "disableSorting='1' />" +  
                             "</row>" +  
                           "</grid>"  
      
        });  
    }  

 

2. 把要改的实体的解决方案导出来,找到RibbonDiffXml这部分,改写CommandDefinitions。

    <CommandDefinition Id="Mscrm.AddExistingRecordFromSubGridAssociated">  
<EnableRules>
<EnableRule Id="Mscrm.AppendPrimary" />
<EnableRule Id="Mscrm.AppendToPrimary" />
<EnableRule Id="Mscrm.EntityFormIsEnabled" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.AddExisting" />
<DisplayRule Id="Mscrm.ShowForManyToManyGrids" />
<DisplayRule Id="Mscrm.AppendPrimary" />
<DisplayRule Id="Mscrm.AppendToPrimary" />
<DisplayRule Id="Mscrm.AppendSelected" />
<DisplayRule Id="Mscrm.AppendToSelected" />
<DisplayRule Id="Mscrm.CanWriteSelected" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="addExistingFromSubGridAccount" Library="$webresource:new_Project">
<CrmParameter Value="SelectedEntityTypeCode" />
<CrmParameter Value="SelectedControl" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>

 

3. 导入改过后的解决方案。发布即可。

注意:

(1) 我在做的过程中先是参考的另一篇文章,他是给1对多关系的,他的DisplayRule有点不一样: <DisplayRule Id="Mscrm.ShowForOneToManyGrids" /> ,

如果我这里这样写,则显示不了按钮了。所以多对多关系的话应该是:<DisplayRule Id="Mscrm.ShowForManyToManyGrids" />

(2) 我之前参考的文章里用了AddExistingRecordFromSubGridStandard和AddExistingRecordFromSubGridAssociated,这样就变成显示两个一样的Add Existing按钮出现了。所以这里应该只用:AddExistingRecordFromSubGridAssociated

(3) 如果发布之后出现这个错误:“To use this saved view, you must remove criteria and columns that refer to deleted or non-searchable items”,可能是因为fetchxml或者layoutxml里的attribute名字写错了,仔细检查一下。

转载于:https://www.cnblogs.com/nixjojo/archive/2012/01/11/2319582.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值