In MS CRM there are some
lookups which allows multiple entities, like Customer lookup.
When clicked on customer lookup,
we have choice to select either account or contact.
But some time requirements are allow
either account or contact only for customer lookup or default customer lookup
to contact instead of account.
Right now there is not any
supported way to achieve this, but with unsupported way you can easily achieve
these requirements.
Note: Below code is unsupported code for MS CRM. JavaScript code is
using DOM.
Add following JavaScript code
on form load.
1.
Customer lookup default to Contact.
function
CustomerLookupDefaultToContact() {
var
customerCtrl = Xrm.Page.getControl("customerid");
customerCtrl.setFocus();
var
customerInput = document.getElementById("customerid_i");
customerInput.setAttribute("lookuptypes",
"2,1"); //2: Contact , 1: Account
customerInput.setAttribute("defaulttype",
2); // Set defaultType
to Contact
customerInput.setAttribute("autoresolve",
2); // Partially entered
name will be resolved with contact record.
customerInput.setAttribute("createpermissiondictionary",
"account:true,contact:true");
customerInput.setAttribute("lookuptypenames",
"account:1:Account,contact:2:Contact");
customerInput.setAttribute("DefaultViewId",
"{A2D479C5-53E3-4C69-ADDD-802327E67A0D}");
// View id to set Default contact view. Replace with your
View Id
}
2.
Customer lookup only for Contacts
function
CustomerLookupOnlyContact() {
var
customerCtrl = Xrm.Page.getControl("customerid");
customerCtrl.setFocus();
var
customerInput = document.getElementById("customerid_i");
customerInput.setAttribute("lookuptypes",
"2"); //2: Contact , 1: Account
customerInput.setAttribute("defaulttype",
2); // Set defaultType
to Contact
customerInput.setAttribute("autoresolve",
2); // Partially entered
name will be resolved with contact record.
customerInput.setAttribute("createpermissiondictionary",
"account:false,contact:true");
customerInput.setAttribute("lookuptypenames",
"contact:2:Contact");
customerInput.setAttribute("DefaultViewId",
"{A2D479C5-53E3-4C69-ADDD-802327E67A0D}");
// View id to set Default contact view. Replace with your
View Id
}
3.
Customer lookup only for Account
function
CustomerLookupOnlyAccount() {
var
customerCtrl = Xrm.Page.getControl("customerid");
customerCtrl.setFocus();
var
customerInput = document.getElementById("customerid_i");
customerInput.setAttribute("lookuptypes",
"1"); //2: Contact , 1: Account
customerInput.setAttribute("defaulttype",
1); // Set defaultType
to Contact
customerInput.setAttribute("autoresolve",
1); // Partially entered
name will be resolved with contact record.
customerInput.setAttribute("createpermissiondictionary",
"account:false,contact:true");
customerInput.setAttribute("lookuptypenames",
"account:1:Account");
customerInput.setAttribute("DefaultViewId",
"{A9AF0AB8-861D-4CFA-92A5-C6281FED7FAB}");
// Default view to show records. Replace with your View Id
}