zoukankan      html  css  js  c++  java
  • 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名字写错了,仔细检查一下。

  • 相关阅读:
    迪杰斯特拉(Dijkstra)算法描述及理解
    KMP初步
    网络流初步
    Cutting Codeforces Round #493 (Div. 2)
    优先队列小结
    树状数组初步理解
    分块思想
    树状数组-逆序对-HDU6318
    线段树
    8.12.5
  • 原文地址:https://www.cnblogs.com/nixjojo/p/2319582.html
Copyright © 2011-2022 走看看