MSCRM 2013: addCustomFilter to field with multiple return types RRS feed

  • General discussion

  • I want to add a custom filter to the customerid field on opportunity. The problem is that the lookup can return Accounts and Contacts, etc. We only associate opportunities to Accounts, but when I add the filter, I get an error like:

    <Message>'Contact' entity doesn't contain attribute with Name = 'hdm_subaccount'.</Message>

    hdm_subaccount is a field name on Account.

    Is there a way to enforce only Accounts being returned and filtered?

            function SetAccountLookup(lookupfield) {
                // Possible account types
                function AccountFilter(lookupctrl, viewid) {
                    var fetchXml = '';
                    fetchXml +=
                    '<filter type="and">' +
                    '<condition attribute="statecode" operator="eq" value="0" />' +
                    '<condition attribute="hdm_subaccount" operator="ne" value="1" />' +
                    '<condition attribute="customertypecode" operator="in">' +
                    '<value>3</value>' +
                    '<value>8</value>' +
                    '<value>200005</value>' +
                    '<value>200007</value>' +
                    '<value>200008</value>' +
                    '</condition>' +
                var lookupctrl = Xrm.Page.getControl(lookupfield);
                lookupctrl.addPreSearch(function () { AccountFilter(lookupctrl, lookupctrl.getDefaultView()); })


    Thursday, January 22, 2015 9:36 PM

All replies

  • Refer this.

    Regards, Saad

    Friday, January 23, 2015 4:56 AM
  • Thanks, that didn't really help me so I ended up using addCustomView instead and catch the selection, should the user use another view to select an 'illegal' record.


    Friday, January 23, 2015 9:20 PM