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) {
lookupctrl.setDefaultView(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>' +
'</filter>'
lookupctrl.addCustomFilter(fetchXml);
}
var lookupctrl = Xrm.Page.getControl(lookupfield);
lookupctrl.addPreSearch(function () { AccountFilter(lookupctrl, lookupctrl.getDefaultView()); })
}
Per