So fügen Sie gefilterte Ansicht zur Taste „Vorhandener Hinzufügen vorhanden“ hinzu

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

  •  25-10-2019
  •  | 
  •  

Frage

Ich habe ein Subgrid, das eine n: n -Beziehung zum aktuellen Datensatz ist.

Ich möchte eine gefilterte Ansicht zur Schaltfläche "Vorhandener" dieses Subgrids hinzufügen.

Irgendeine Idee?

(Ich habe diesen Artikel verfolgt, der genau wie meine Anforderungen entspricht: http://danielcai.blogspot.com/2011/12/filtered-lookup-for-existing-button-of.html)

War es hilfreich?

Lösung

Zunächst müssen Sie eine Lösung exportieren, die die Entität mit dem Typ enthält, den Sie filtern möchten:

In dem Anpassungen.xml finde die RibbondiffXML Knoten und fügen Sie den folgenden Code hinzu:

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

Und im der Kommandodefinitionen Knoten, fügen Sie Folgendes hinzu:

<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>

Der Code stammt aus einer XML -Datei, die Sie im CRM 2011 SDK finden können, und wurde so geändert, dass sie eine benutzerdefinierte Funktion von einer benutzerdefinierten JavaScript -Bibliothek aufrufen.

Erstellen Sie dann die neue JS -Bibliothek mit dem oben angegebenen Namen in den Bibliotheksattributen.

Fügen Sie eine erste generische Funktion hinzu:

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

Fügen Sie schließlich die Funktion hinzu, die von der Schaltfläche aufgerufen werden sollte:

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

Veröffentlichen Sie alles und es sollte in Ordnung sein!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top