Как добавить фильтрованное представление к кнопке ленты «Добавить существующий»

StackOverflow https://stackoverflow.com/questions/8800905

  •  25-10-2019
  •  | 
  •  

Вопрос

У меня есть подсег, которая является N: N отношением к текущей записи.

Я хочу добавить отфильтрованное представление к кнопке «Добавить существующий» этого подмета.

Есть идеи?

(Я следил за этой статьей, которая точно такая, как мои требования: http://danielcai.blogspot.com/2011/12/filtered-lookup-for-ureciisting-button-of.html)

Это было полезно?

Решение

Во -первых, вы должны экспортировать решение, содержащее объект с типом, который вы хотите отфильтровать:

в настройка.xml Найди Ribbondiffxml Узел и добавьте следующий код:

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

И в CommandDefinitions Узел, добавьте это:

<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, который вы можете найти в SDK CRM 2011 и был изменен для вызова пользовательской функции из пользовательской библиотеки JavaScript.

Затем создайте новую библиотеку JS с именем, указанным выше в атрибутах библиотеки.

Добавьте первую общую функцию:

/*****************************************/
/*                                       */
/*      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);
    }
}

и, наконец, добавьте функцию, которую следует вызвать кнопкой:

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>'
    });
}

Публикуйте все, и все должно быть в порядке!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top