Dynamically changing the way a CRM Lookup field works is something that most developers come across, especially when they want to:
The steps to customize a CRM Lookup field are as follows:
- Filter the records that are displayed in the Lookup window
- Change the columns displayed in the Lookup window
- Change the entity type
The steps to customize a CRM Lookup field are as follows:
- function CustomLookup() {
- //1. Random Guid
- var viewId = "{1BFB2B35-B07C-44D1-868D-258DEEAB88E2}";
- //2. The Display Name of the View
- var viewDisplayName = "My Accounts";
- //3. The Entity Type that you want the Lookup to us
- var entityName = "account"; e
- //4. The FetchXml Query which is executed to return the data to the Lookup window
- var cFetchXml =
- "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
- "<entity name='" + entityName + "'>" +
- "<attribute name='name' />" +
- "<attribute name='accountid' />" +
- "<order attribute='name' descending='false' />" +
- "<filter type='and'>" +
- "<condition attribute='name' operator='in' >" +
- "<value>Microsoft</value>" +
- "<value>Salesforce</value>" +
- "<value>Oracle</value>" +
- "</condition>" +
- "</filter>" +
- "</entity>" +
- "</fetch>";
- //5. Layout - this section defines which columns are displayed, width of the column etc
- var cGridLayout =
- "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
- "<row name='result' id='accountid'>" +
- "<cell name='name' width='100' />" +
- "</row>" +
- "</grid>";
- $("#lookupControlId").attr("disableViewPicker", "0");
- //6. Add the Custom Lookup
- Xrm.Page.getControl("lookupControlId").addCustomView(viewId,
- entityName,
- viewDisplayName,
- cFetchXml,
- cGridLayout,
- true);
- $("#lookupControlId").attr("disableViewPicker", "1");
- }
No comments:
Post a Comment