Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7089861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:58:26+00:00 2026-05-28T07:58:26+00:00

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

  • 0

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.

Any idea?

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:58:26+00:00Added an answer on May 28, 2026 at 7:58 am

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

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

      <RibbonDiffXml>
        <CustomActions />
        <Templates>
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
        </Templates>
        <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>
    

    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.

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

    Add a first generic function:

    /*****************************************/
    /*                                       */
    /*      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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview data and this gridview have subgrid too. in the first
I have a jqGrid with a subgrid. I want to sort the subgrid so
Hi I have a jqgrid with a subgrid which calls into a servlet. I
Have any one tried to activate fancybox thumbnail gallery using a button or an
I have a jqGrid (4.1.1) using a simple subgrid. When a record is plus-ed
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
I have a jqgrid that has a subgrid. How can I expand the subgrid
I have a jqgrid with a subgrid. I am attempting to apply different colors
Have converted devise new session from erb to Haml but doens't work, this is
have anyone can tell me what syntax error on this actionscript (actionscript3.0)? var rotY:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.