locked
CRM 2011 Filtered Subgrid Error RRS feed

  • Question

  • Hi

    I cant get my head around this error.

    I'm trying to filter a subgrids "Add existing..."-button. The relationship is a N:N and my code looks like this:

    function addExistingFromSubGridCustom(params) 
    {
    
        var relName = params.gridControl.getParameter("relName"),
            roleOrd = params.gridControl.getParameter("roleOrd"),
            viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}"; // a dummy view ID
    
        var customView = 
        {
            fetchXml: params.fetchXml,
            id: viewId,
            layoutXml: params.layoutXml,
            name: params.name,
            recordType: params.gridTypeCode,
            Type: 0
        };
             alert(relName);
            alert(roleOrd);
            alert(params.fetchXml);
            alert(params.layoutXml);
            alert(params.gridTypeCode);
    
        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.
    
        //var primaryEntityName2  = "client";
    
    //    if (primaryEntityName != "client") 
    //    {
    //        Mscrm.GridRibbonActions.addExistingFromSubGridStandard(gridTypeCode, gridControl);
    //        return;
    //    }
    
        //Get a lookup value
        var lookupItem = new Array();
        lookupItem = Xrm.Page.getAttribute("log_account").getValue();
        if (lookupItem != null) 
        {
            var guid = lookupItem[0].id;
            var name = lookupItem[0].name;
        }
    
        //Update the fetch that will be used by the grid.
        var fetch = '<fetch version="1.0" output-format="xml-platform" mapping="logical">' +
                    '<entity name="contact">' +
                    '<attribute name="contactid" />' +
                    '<attribute name="telephone2" />' +
                    '</entity>' +
                    '</fetch>';
        // Add conditions to your fetch xml dynamically
        // Call the generic method with the rights arguments. 
        addExistingFromSubGridCustom({
            gridTypeCode: gridTypeCode,
            gridControl: gridControl,
            fetchXml: fetch,
            layoutXml: '<grid name="resultset" object='+gridTypeCode+'  jump="telephone2" select="1" icon="1" preview="1">' +
                    '<row name="result" id="contactid">' +
                        '<cell name="telephone2" width="250"/>' +
                        '</row>' +
                    '</grid>',
                    name: 'Custom Search View'
        });
    }
    

    The FetchXML here is just to try something more simpler then what I want, but even here it gives me an error

    I also changed the XML on the button as I suppose to:

    <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:log_filteredsubgrid">
                    <CrmParameter Value="SelectedEntityTypeCode" />
                    <CrmParameter Value="SelectedControl" />
                    <CrmParameter Value="PrimaryEntityTypeName" />
                  </JavaScriptFunction>
                </Actions>
              </CommandDefinition>

    Can anyone help me with what the problem could be?

    I'm getting the error when I push the button. First it gives me an "Error has occurred" pop up and after that a "Record is unavailable"-popup.

    I have tried to debug the javascript, and the error is this line:

    var lookupItems = LookupObjects(null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);

    Tuesday, January 8, 2013 2:51 PM

Answers

  • Hi,
       You missed placing double quotes for the "object" attribute value in the layout xml. See the image for the same.  I hope it helps you.

    layoutXml: '<grid name="resultset" object='+gridTypeCode+'  jump="telephone2" select="1" icon="1" preview="1">' +

      

    Vikranth http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"

    • Marked as answer by Casper Schau Thursday, January 10, 2013 8:05 AM
    Thursday, January 10, 2013 7:00 AM

All replies

  • I really dont understand this problem. It must be an issue with the FetchXML or the LayoutXML but both seems ok I think?
    Tuesday, January 8, 2013 5:07 PM
  • Bump. I still need help for this issue.
    Wednesday, January 9, 2013 12:38 PM
  • Hi,
        What are you trying to achieve by changing the "Add Existing" button's view? If you are only trying to change the fetchxml then following post will help you.

    http://crmgreenbible.blogspot.sg/2011/07/crm-2011-change-subgrid-fetchxml.html?showComment=1315336674024

     


    Vikranth http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"

    Wednesday, January 9, 2013 2:15 PM
  • Hi Vikranth

    Ty for answering my question.

    What I want to achieve is to change the fetchxml which is behind the "Add existing"-button.

    My scenario is that I have an account lookup-field and a contact-subgrid on an custom entity. I would like that when I push the "Add existing"-button for the contact subgrid, that the contacts im presented with is only the ones which is connected to the account, which is in the lookup field.

    The link you provided only changes the fetchxml for the subgrid, which isnt exactly what I want to achieve, but ty anyway.

    Anyones help is welcomed

    Wednesday, January 9, 2013 3:18 PM
  • Hi,
       You missed placing double quotes for the "object" attribute value in the layout xml. See the image for the same.  I hope it helps you.

    layoutXml: '<grid name="resultset" object='+gridTypeCode+'  jump="telephone2" select="1" icon="1" preview="1">' +

      

    Vikranth http://howto-mscrm.blogspot.com "Please Mark it as answer if it helps in resolving your query"

    • Marked as answer by Casper Schau Thursday, January 10, 2013 8:05 AM
    Thursday, January 10, 2013 7:00 AM
  • Ah wonderfull. Ty Vikranth, it was the issue. I really go blind on this javascript sometimes......
    Thursday, January 10, 2013 8:05 AM
  • Hi Vicky,

    Can you please guide how to implement it

    Thursday, December 19, 2013 8:36 AM