Friday, 19 July 2013

CRM 2011 - Custom Lookup Example

Dynamically changing the way a CRM Lookup field works is something that most developers come across, especially when they want to:
  1. Filter the records that are displayed in the Lookup window
  2. Change the columns displayed in the Lookup window
  3. Change the entity type
Regardless of the requirement, the only way to customize a CRM Lookup field is to use client-side JScript/JavaScript.

The steps to customize a CRM Lookup field are as follows:

  1. function CustomLookup() {
  2.  
  3.     //1. Random Guid
  4.     var viewId = "{1BFB2B35-B07C-44D1-868D-258DEEAB88E2}";
  5.  
  6.     //2. The Display Name of the View
  7.     var viewDisplayName = "My Accounts";
  8.  
  9.     //3. The Entity Type that you want the Lookup to us
  10.     var entityName = "account";                             e
  11.  
  12.     //4. The FetchXml Query which is executed to return the data to the Lookup window
  13.     var cFetchXml =
  14.                 "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
  15.                 "<entity name='" + entityName + "'>" +
  16.                     "<attribute name='name' />" +
  17.                     "<attribute name='accountid' />" +
  18.                     "<order attribute='name' descending='false' />" +
  19.                     "<filter type='and'>" +
  20.                         "<condition attribute='name' operator='in' >" +
  21.                             "<value>Microsoft</value>" +
  22.                             "<value>Salesforce</value>" +
  23.                             "<value>Oracle</value>" +
  24.                         "</condition>" +
  25.                     "</filter>" +
  26.                  "</entity>" +
  27.                 "</fetch>";
  28.  
  29.     //5. Layout - this section defines which columns are displayed, width of the column etc
  30.     var cGridLayout =
  31.         "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
  32.             "<row name='result' id='accountid'>" +
  33.                 "<cell name='name' width='100' />" +
  34.             "</row>" +
  35.         "</grid>";
  36.     
  37.     $("#lookupControlId").attr("disableViewPicker", "0");
  38.  
  39.     //6. Add the Custom Lookup
  40.     Xrm.Page.getControl("lookupControlId").addCustomView(viewId,
  41.         entityName,
  42.         viewDisplayName,
  43.         cFetchXml,
  44.         cGridLayout,
  45.         true);
  46.  
  47.     $("#lookupControlId").attr("disableViewPicker", "1");
  48. }

 

Action Microsoft.Crm.Setup.Common.Analyzer +CollectAction failed. Fatal error during installation

When installing the Srs Data Connection (Microsoft Dynamics CRM Reporting Extensions), you may have experienced the following error: ...