如何将过滤的视图添加到功能区“添加现有”纽扣 [英] How to add filtered view to Ribbon "Add Existing" button

查看:33
本文介绍了如何将过滤的视图添加到功能区“添加现有”纽扣的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与当前记录具有n:n关系的子网格。

I have a subgrid which is n:n relationship to current record.

我想向该子网格的添加现有按钮添加过滤视图。

I want to add a filtered view to the "Add Existing" button of this subgrid.

有什么想法吗?

(我按照这篇与我的要求完全相同的文章进行了操作: http://danielcai.blogspot.com/2011/12/filtered -lookup-for-existing-button-of.html

(I followed this article which is exactly same as my requirements: http://danielcai.blogspot.com/2011/12/filtered-lookup-for-existing-button-of.html)

推荐答案

首先,您必须导出解决方案包含要过滤类型的实体:

First, you have to export a solution containing the entity with the type you want to filter:

customizations.xml 中找到 RibbonDiffXml 节点,然后添加以下代码:

In the customizations.xml find the RibbonDiffXml node and add the following code:

  <RibbonDiffXml>
    <CustomActions />
    <Templates>
      <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
    </Templates>
    <CommandDefinitions />

然后在 CommandDefinitions 节点中添加以下内容:

And in the the CommandDefinitions node, add this:

<CommandDefinitions>
  <CommandDefinition Id="Mscrm.AddExistingRecordFromSubGridAssociated">
    <EnableRules>
      <EnableRule Id="Mscrm.AppendToPrimary" />
      <EnableRule Id="Mscrm.EntityFormIsEnabled" />
    </EnableRules>
    <DisplayRules>
      <DisplayRule Id="Mscrm.AddExisting" />
      <DisplayRule Id="Mscrm.ShowForManyToManyGrids" />
      <DisplayRule Id="Mscrm.AppendToPrimary" />
      <DisplayRule Id="Mscrm.AppendSelected" />
      <DisplayRule Id="Mscrm.CanWriteSelected" />
    </DisplayRules>
    <Actions>
      <JavaScriptFunction FunctionName="addExistingCustomFilter" Library="$webresource:new_yourLibrary">
        <CrmParameter Value="SelectedEntityTypeCode" />
        <CrmParameter Value="SelectedControl" />
        <CrmParameter Value="PrimaryEntityTypeName" />
      </JavaScriptFunction>
    </Actions>
  </CommandDefinition>
  <CommandDefinition Id="Mscrm.AddExistingRecordFromSubGridStandard">
    <EnableRules>
      <EnableRule Id="Mscrm.AppendToPrimary" />
      <EnableRule Id="Mscrm.EntityFormIsEnabled" />
    </EnableRules>
    <DisplayRules>
      <DisplayRule Id="Mscrm.AddExisting" />
      <DisplayRule Id="Mscrm.ShowForManyToManyGrids" />
      <DisplayRule Id="Mscrm.AppendToPrimary" />
      <DisplayRule Id="Mscrm.AppendSelected" />
      <DisplayRule Id="Mscrm.CanWriteSelected" />
    </DisplayRules>
    <Actions>
      <JavaScriptFunction FunctionName="addExistingCustomFilter" Library="$webresource:new_yourLibrary">
        <CrmParameter Value="SelectedEntityTypeCode" />
        <CrmParameter Value="SelectedControl" />
        <CrmParameter Value="PrimaryEntityTypeName" />
      </JavaScriptFunction>
    </Actions>
  </CommandDefinition>
</CommandDefinitions>

代码来自XML文件,您可以在CRM 2011 SDK中找到该文件,并将其修改为

The code comes from an XML file that you can find in the CRM 2011 SDK and has been modified to call a custom function from a custom Javascript Library.

然后,使用库属性中上面指定的名称创建新的JS库。

Then, create the new JS library with the name specified above in the Library attributes.

添加第一个通用函数:

/*****************************************/
/*                                       */
/*      Add Custom View To Subgrid       */
/*                                       */
/*****************************************/
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: params.name,
        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);
    }
}

最后,添加应由调用的函数按钮:

and finally, add the function which should be called by the button:

function addExistingCustomFilter(gridTypeCode, gridControl, primaryEntityName) {

// Here you can specify for which entity the filter should be applied.
// For example, filter only when you try to add an existing record to a client.
// In the other cases, you will call the default method.
    if (primaryEntityName != "client" ) {
        Mscrm.GridRibbonActions.addExistingFromSubGridStandard(gridTypeCode, gridControl);
        return;
    }

    // Add some logic to retrieve information needed to filter your view if you want to


    //Update the fetch that will be used by the grid.
    var fetch = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">' +
                '<entity name="...">' +
                '<attribute name="..." />' +
                '<filter type="and">' +
                '<condition ... />' +
                '</filter>' +
                '</entity>' +
                '</fetch>';
    // Add conditions to your fetch xml dynamically

    // Call the generic method with the rights arguments. 
    addExistingFromSubGridCustom({
        gridTypeCode: gridTypeCode,
        gridControl: gridControl,
        fetchXml: fetch,
        name: "My dynamyc custom filtered view!",
        layoutXml: '<grid name="" object="' + gridTypeCode + '"  jump="all_name" select="1" icon="1" preview="0">' +
               // Provide a layout xml ...
              '</grid>'
    });
}

发布所有内容,应该没问题!

Publish everything and it should be ok!

这篇关于如何将过滤的视图添加到功能区“添加现有”纽扣的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆