locked
CRM 2011 Filtered Lookup view error: The type mismatach. RRS feed

  • Question

  • Hello,

    This is my JavaScript code for filtering lookup field, which I've been used for many time in other project.

    function contactFilterLookupView(contact) {
        var ReturnedTypeCode = null;
        var LayoutXml = null;
        var legalName = Xrm.Page.getAttribute("ig_legalnameofclientid").getValue();
        var condition = "";
        if (legalName != null) {
            condition = legalName[0].id;
        }
        var viewIdOrig = Xrm.Page.getControl(contact).getDefaultView();
        var viewId = "{BB657E25-DCE8-41AA-AC9B-FFA031D5FDED}";
        var viewDisplayName = "Filtered View";
        var fetchXml = "";
    
        fetchXml +="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>";
        fetchXml +="<entity name='contact'>                                                              ";
        fetchXml +="<attribute name='fullname' />                                                        ";
        fetchXml += "<attribute name='parentcustomerid' />                                                      ";
        fetchXml += "<attribute name='address1_city' />                                                      ";
        fetchXml += "<attribute name='address1_telephone1' />                                                       ";
        fetchXml += "<attribute name='telephone1' />                                                       ";
        fetchXml += "<attribute name='emailaddress1' />                                                       ";
        fetchXml +="<attribute name='contactid' />                                                       ";
        fetchXml +="<order attribute='fullname' descending='false' />                                    ";
        fetchXml +="<filter type='and'>                                                                  ";
        fetchXml +="<condition attribute='parentcustomerid' operator='eq' value='"+condition+"' />       ";
        fetchXml +=" </filter>                                                                           ";
        fetchXml +="</entity>                                                                            ";
        fetchXml +="</fetch>                                                                             ";
                                                                                                       
        var context = Xrm.Page.context;
        var queryUrl = context.getServerUrl() + ODATA_ENDPOINT + "/SavedQuerySet(guid'" + viewIdOrig + "')";
        if (ReturnedTypeCode == null) {
            $.ajaxSetup({ "async": false });
            var jqxhr = $.getJSON(queryUrl, function (data) {
                ReturnedTypeCode = data.d.ReturnedTypeCode;
                LayoutXml = data.d.LayoutXml;
            }).error(errorHandler);
            $.ajaxSetup({ "async": true });
               
        }
        Xrm.Page.getControl(contact).addCustomView(viewId, ReturnedTypeCode, viewDisplayName, fetchXml, LayoutXml, true);
    }

    But for my current project,  it throw a message 'The type mismatch' at last line

    Xrm.Page.getControl(contact).addCustomView(viewId, ReturnedTypeCode, viewDisplayName, fetchXml, LayoutXml, true);

    I check the fetchXml and LayoutXml column doesn't match, but even I change them manully to match each other, it still throws the same message 'Type mismatch' on page load.(it's being run under OnLoad function).

    Any ideas?

    Thanks.


    Friday, July 19, 2013 2:32 PM

Answers

  • I found the issue. it's nothing related to this filtered view function. it comes from the 'onclick' event on form load. For whatever reason, this function can't be called by that onclick event on page load.
    • Marked as answer by howexg9 Thursday, July 25, 2013 4:18 PM
    Thursday, July 25, 2013 4:18 PM

All replies

  • Hi

    What is the returned value of ReturnedTypeCode after your ajax query?

    Friday, July 19, 2013 9:01 PM
  • contact entity name 'contact'.
    Monday, July 22, 2013 6:10 PM
  • I found the issue. it's nothing related to this filtered view function. it comes from the 'onclick' event on form load. For whatever reason, this function can't be called by that onclick event on page load.
    • Marked as answer by howexg9 Thursday, July 25, 2013 4:18 PM
    Thursday, July 25, 2013 4:18 PM