问题
The CustomerId field that comprises both the Account and Contact records defaults to the Contact Quick Form when creating new records from a Lookup field of that type.
How can I get the field to instead default to the Account Quick Form?
回答1:
I encountered the same request from a client recently and after some unsuccessful searches we decided that we replace the field on the Form with Account field. Even though there is a Customer filed, there are 2 seperate fields to store Account and Contact by default in CRM.
Therefore we just removed/hid the customer field on the form and added the Account field. Once you populate the Account field, the customer field gets automatically populated.
Hope this helps.
回答2:
This is what I've done to set up the Customer lookup to show only Contact records.
function Form_OnLoad()
...
preFilterLookup();
..
}
function preFilterLookup() {
Xrm.Page.getControl("customerid").addPreSearch(addLookupFilter);
}
function addLookupFilter() {
document.getElementById("customerid_i").setAttribute("lookuptypenames", "contact:2:Contact");
document.getElementById("customerid_i").setAttribute("lookuptypes", "2");
}
In case you want to add a filter to the records:
function addLookupFilter() {
document.getElementById("customerid_i").setAttribute("lookuptypenames", "contact:2:Contact");
document.getElementById("customerid_i").setAttribute("lookuptypes", "2");
var account = Xrm.Page.getAttribute("aux_account").getValue();
if (account != null) {
var filter = "<filter type='and'>" + "<condition attribute='parentcustomerid' operator='eq' value='" + account[0].id + "' /></filter>";
Xrm.Page.getControl("customerid").addCustomFilter(filter);
}
}
So, the changes I've done to migrate from CRM 2011 to 2013 are:
Add _i when you get the element by: document.getElementById("customerid_i")
Use new methods: addPreSearch
and addCustomFilter
You can check these in msdn documentation and easily change code to show only Accounts.
来源:https://stackoverflow.com/questions/24856169/how-do-i-change-the-default-quick-form-for-the-customerid-field-in-dynamics-crm