Creating a Custom Filtered Lookup in CRM 2011

When implementing Microsoft Dynamics CRM, you may have a requirement where you need to see a selection of records filtered to only records that are associated with an earlier user selection. Some of these filters can be achieved using out-of-the-box customizations. But in some cases, you might need to achieve this by implementing some simple customizations in CRM.

Today we'll explain how to implement a custom filtered lookup using simple customizations. This can be used in any out-of-the-box or custom entity.

Let's say that in the Account entity, when a user selects a primary contact, you want to show the user only those contacts associated to the selected parent account as a default view. This can be achieved by using some JavaScript in CRM. The following Xrm.Page.ui control object methods provide us a way to implement custom filtered lookups for a lookup field in CRM:

addCustomViewAdds a new view for the lookup control
setDefaultViewSets the default view for the lookup control
getDefaultViewReturns the ID(GUID) value of the default view of the lookup control

The code snippet below does the magic of creating the custom filtered lookup:

var availableDefaultViewId;
// FUNCTION: formOnLoad
function formOnLoad(parentAccountFieldName,primContactFieldName) {
    availableDefaultViewId = Xrm.Page.getControl(parentAccountFieldName).getDefaultView();
  setPrimaryContactLookup(parentAccountFieldName, primContactFieldName, false);

// FUNCTION: setPrimaryContactLookup
function setPrimaryContactLookup(parentAccountFieldName, primContactFieldName, resetSelection) {
    // Get the selected parent account Id    
    var parentAccount = Xrm.Page.getAttribute(parentAccountFieldName).getValue();
    if (parentAccount != null) {
        var parentAccountid = parentAccount[0].id;
        var parentAccountname = parentAccount[0].name;
        if (resetSelection == true) {
            // reset old selection for Procedure Code        
        // use randomly generated GUID Id for our new view      
        var viewId = "{6fd72744-3676-41d4-8003-ae4cde9ac282}";
        var entityName = "contact";
        // give the custom view a name      
        var viewDisplayName = "Associated contacts for " + parentAccountname + "";

        // find all associated contacts of the selected parent account
        var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
                            "<entity name='contact'>" +
                                "<attribute name='contactid' />" +
                                "<attribute name='fullname' />" +
                                "<attribute name='emailaddress1' />" +
                                "<attribute name='telephone1' />" +
                                "<attribute name='telephone2' />" +
                                "<attribute name='address1_line1' />" +
                                "<attribute name='address1_line2' />" +
                                "<attribute name='address1_city' />" +
                                "<attribute name='address1_stateorprovince' />" +
                                "<attribute name='address1_postalcode' />" +
                                " <order attribute='fullname' descending='false' />" +
                                "<filter type='and'>" +
                                    "<condition attribute='parentcustomerid' operator='eq' value='" + parentAccountid + "'  />" +
                                "</filter>" +
                              "</entity>" +

        // build Grid Layout     
        var layoutXml = "<grid name='resultset' " +
                        "object='1' " +
                        "jump='contactid' " +
                        "select='1' " +
                            "icon='1' " +
                            "preview='1'>" +
                            "<row name='result' " +
                            "id='contactid'>" +
                            "<cell name='fullname' " +
                            "width='200' />" +
                            "<cell name='emailaddress1' " +
                            "width='200' />" +
                           "<cell name='telephone1' " +
                            "width='100' />" +
                            "<cell name='telephone2' " +
                            "width='100' />" +
                            "<cell name='address1_line1' " +
                            "width='150' />" +
                            "<cell name='address1_line2' " +
                            "width='150' />" +
                            "<cell name='address1_city' " +
                            "width='150' />" +
                            "<cell name='address1_stateorprovince' " +
                            "width='100' />" +
                            "<cell name='address1_postalcode' " +
                            "width='100' />" +
                            "</row>" +

        // add the Custom View to the primary contact lookup control      
        Xrm.Page.getControl(primContactFieldName).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
    else {
        // no parent account is selected, reset primary contact Lookup View to the default view


Here are the steps to implement the custom filtered lookup for the primary contact in the account form:

  1. Add the above code snippet as a web resource in CRM.
  2. Navigate to Settings > Customization.
  3. Launch the working solution, or if you do not have one, either create one or click on Customize the System.
  4. Navigate to the account entity for which you want to add this custom filtered lookup.
  5. Access the Account form.

    custom filtered lookup in CRM 2011

  6. In the form that opened, double click on the Form Properties button at the top.

  7. In the popup that opens up, add the web resource you have created in step 1.

  8. Go to the form OnLoad event, click Add, and call the formOnLoad function by passing the parent account and primary contact field names as parameters.

    This is the form OnLoad event screen shot after calling the function:

  9. Go to the OnChange event of the Parent Account field and call the setPrimaryConatactLookup function by passing the parent account and primary contact field names, true as parameters.

  10. Save the changes.
  11. Publish customizations.

    After implementing all these steps, once you click on the lookup icon of the Primary Contact field, you should see the custom filtered lookup created for the Primary Contact as shown in the screenshot below.


We hope this was helpful! If you need assistance with anything related to Microsoft Dynamics CRM, we've got a great support team and we're happy to help.

Happy CRM'ing!

Displaying a Filtered View in the Site Map in CRM 2011

Most organizations use Dynamics CRM to track their Accounts and Contacts, but they also track other companies with whom they work. It's common to use the Relationship Type field on the Account to indicate that a company is a Partner, Consultant, Investor or Vendor. That way it is easy to create a View that filters the data based on the type of Account. But wouldn't it be great to have its own menu item on the left navigation in CRM? By modifying the site map and adding some parameters from a View, we can accomplish this task!

In this example, we are going to use the Account entity and the out-of-the-box relationship type field.

1. Create a new View that will have filter of relationship type = Vendor. This can be a System View (recommended) or a Personal View. If you do use a Personal View, make sure you share the View with the appropriate user who will need to have access to this menu.

Display a filtered view in the site map | CRM 2011

2. Once the view has been created and published, we need to grab a couple of pieces of information. Go to the Accounts entity and pull up the view that we created in step 1. Select the Copy a Link and select the Current View option.

Displaying a Filtered View in the Site Map in CRM 2011

3. Now copy that link to a notepad, as we will need some information from that link. Below is an example of what it would look like.

Active Vendors < /xyz.aspx?etc=1&extraqs=%3fpagemode%3diframe%26sitemappath%3dWorkplace%257cCustomers%257cnav_accts&pagetype=entitylist&viewid=%7bDFBDFC4E-1781-E211-BC15-000C298A36A7%7d&viewtype=4230>

4. The next step is that we need to export the existing site map. Go to Settings, Customizations and Solutions. From here, you can create a new solution. Provide a display name, publisher and a version. Then click Save.

Displaying a Filtered View in the Site Map in CRM 2011

5. After the screen refreshes, we can select the "Add Existing" and then select the site map. Once the site map has been added, we can select "Export Solution" from the top menu. That will walk you through a wizard and allow you to save that solution to your local PC.

Displaying a Filtered View in the Site Map in CRM 2011

6. Locate the solution file we exported in the above step, and extract files that are included in the zip file.

7. Find the Customizations.xml file and open this file in Notepad, Notepad ++ or Visual Studio. (If possible, Visual Studio or Notepad ++ are the best program to make these changes.) This will give you the ability to make sure there are no errors in your XML file before uploading it back to CRM.

Displaying a Filtered View in the Site Map in CRM 2011

8. In this example, we want the new menu item to be displayed under My Work and under the sub-section of Customers. In the customizations.xml file, find a Group ID of "Customer".

Displaying a Filtered View in the Site Map in CRM 2011

9. Copy the information below to the XML right below the SubArea for Contacts.

<SubArea Id="new_vendor" Url="/_root/homepage.aspx?etn=account&amp; viewid=%7bDFBDFC4E-1781-E211-BC15-000C298A36A7%7d&amp;viewtype=1039">
<Title LCID="1033" Title="Vendors" />

10. Let's now look at what needs to be updated in the string above to look at your specific information from CRM.

  1. Etn = account
    1. Here we specify the entity that we are pulling the view from. Since we are using the account entity in this example, we can leave this as is.
  2. Viewid= the GUID of the view
  3. Viewtype = this will be one of two options.
    1. For system views enter in 1039
    2. For Personal views enter in 4230
  4. Title="Vendors"
    This will be the name that appears in the Site Map. This can be changed to display whatever value you would like to have displayed.

<SubArea Id="new_vendor" Url="/_root/homepage.aspx?etn=account&amp; viewid=%7bDFBDFC4E-1781-E211-BC15-000C298A36A7%7d&amp;viewtype=1039"><Titles>
<Title LCID="1033" Title="Vendors" />

11. Save your customizations.xml file and create a zip file that includes all three files that were extracted in Step 6.

Displaying a Filtered View in the Site Map in CRM 2011

12. Now it is time to upload the solution to CRM. Go to Settings, Solutions and select Import.


13. Browse to the zip file we created in step 11 and walk through the Solution Wizard. Once the import finishes, select the Publish All Customizations. When that has finished, refresh your browser by clicking the refresh button or F5.

14. Once your screen refreshes you will now see a new menu item called Vendors.

Displaying a Filtered View in the Site Map in CRM 2011
A filtered view like this is just one of many examples of modifying the Site Map to make your Dynamics CRM more user friendly. If you are not familiar with XML code or need assistance in modifying your Site Map, contact PowerObjects and they will be than happy to assist you.

Happy CRM'ing!

Filter Your CRM 2011 System Views Dynamically

Is your view list overflowing? Is it difficult to find the views that are meaningful for you? Do you wish you could filter your CRM 2011 system views dynamically?

First of all, let's go through the out of the box configuration options in CRM 2011 that will help most of the cases:

If the above hints are not enough—for example, if you need to hide certain views dynamically based on business rules or security roles—you will need a custom plugin.

For example, your Opportunity view list might look like following:

Too many CRM 2011 System Views

But if you have a clear separation between the department handling New Opportunities and the department handling Renewals, the other department's views are nothing but distraction. We really want to check for the membership in a security role, team or business unit and dynamically show/hide views that are meaningful.

We can achieve this by using the RetrieveMultiple plugin against savedquery, registered on the pre-operation step. The idea of the plugin is that we attach additional criteria to the existing query. The easiest way to filter the views is by referencing something in the description. For example, our plugin filters to views that have 'Renewal' in the description:

Viola! CRM 2011 System Views for Renewals Only!

Additionally, we could have a similar plugin in RetrieveMultiple for savedquery in the post-operation step, to dynamically set the default view. However, we do not recommend this as it would override the functionality from out of the box user level default views and pinned views.

Note that the idea spans from our CRM 4.0 blog Dynamic System Views in Microsoft CRM 4.0.

However, the plugin did need several changes in order to work and be optimized for CRM 2011.

Hope you have fun things planned for the holidays, and happy CRM'ing!

Microsoft Dynamics CRM Pre-Filtering for CRM Reporting

CRM Pre-filtering is a unique feature provided by Microsoft Dynamics CRM to enable reports to be context sensitive and present the report with the Advanced Find functionality. This will greatly enhance a report.

To make use of it the CRMAF_ alias prefix is simply appending to the query. So instead of:

Select name from FilteredAccount

Change the query to:

Select name from FilteredAccount as CRMAF_Account

While creating the report this capability will not become apparent until posted as a report through the report manager. Using the steps below we will walk through the steps

Follow these steps to complete:

Step 1:

Create a new report, select new table wizard

Create the data source

For the DataSet paste in this query


customeridname, name, owneridname, estimatedclosedate, estimatedvalue, opportunityratingcodename, closeprobability, statecodename



Note: we are not using the CRMAF_ filter yet

It it not necessary at this time to enhance or make costeic change to the report, we are merely exploring this function.

Step 2:

Save the report as: ‘OppsByOwner_noFilter’

Post the report into CRM as new report.

Run the new report and it will immediately render.

Step 3:

Return to the report and open the dataset. Modify the query and append the alias:

AS CRMAF_FilteredOpportunity

Your query should now look like this:


customeridname, name, owneridname, estimatedclosedate, estimatedvalue, opportunityratingcodename, closeprobability, statecodename


FilteredOpportunity AS CRMAF_FilteredOpportunity

Save the report with a ‘Save As’ and name it: ‘OppsByOwner_withFilter’

Pre-Filtering for CRM Reporting

Post as a new report in CRM

Pre-Filtering for CRM Reporting

Run the report.

This time you will be prompted with the default Advanced Find screen!

Simply run the report or add your own criteria

Pre-Filtering for CRM Reporting

Step 4:

Next we will set a default filter.

Select the report and click ‘Edit Default Filter’

Pre-Filtering for CRM Reporting

Set as desired. In our example we will pre-set to ‘Open’

Pre-Filtering for CRM Reporting

Click to ‘Save Default Filter’

Run the report to test.

When running you will now see the ‘Edit Filter’ option. This returns the user to the pre-filter screen to modify their query

Pre-Filtering for CRM Reporting


The pre-filtering option is unique to CRM reports and allows to expand the user experience and reduce time spent report building by empowering the end-user to add their own parameters and filters as their requirements dictate.

Happy CRM’ing!

Microsoft Dynamics CRM Connections and How to Search for Related Records

Microsoft Dynamics CRM Connections provide a flexible way to connect and describe the relationships between two records.

For example, from a Contact record we will create a Connection to another Contact record for a referral.  This is accomplished by opening the Contact record, then clicking on the Connection link, then clicking Connect from the ribbon.  You can then connect to another record or have another record connect to the originating record.

microsoft dynamics CRM connections

After clicking on the To Another link, a popup window is displayed where you can specify the record that you will be connecting to.  You can also specify the As this role which allows you to describe the relationship between the related record.

CRM connections

If you expand the Details section you can see the originating record and its role.

After the record is saved, CRM creates two entries in the Connection table in the database.  Each entry allows you to search for the related record from the originating record or the related record.  If you inspect the Connection table in the database you will notice that there are Record1 and Record2 fields which store the primary keys of the related records (in this case the Contact records) and Record1Role and Record2Role fields which stores the primary keys of the Connection Role.  These are the fields that are used to find how a record is connected to another record.

But which record points to Record1 or Record2?  Because CRM creates two entries, you can choose either one.  In the example above you can say that John Doe points to Record1Id and Jane Doe points to Record2Id or vice versa.  You can determine which to use by the way you start your search for the related record.

For example, in a SQL or Fetch XML query, if you wanted to retrieve fields from the related Jane Doe record you would start from the Contact record of John Doe and join to the Connection record where the ContactId equals Record1Id and then join back to the Contact record where the Connection’s Record2Id equals the ContactId of Jane Doe.

The Connection Role allows you to filter further.  If John Doe is connected to various records with different roles you can use the Record1RoleId or Record2RoleId to only retrieve the type of relationship you are looking for (You again determine which Record1Role or Record2Role to use by the direction that you chose to start your connection).

In the example above, John Doe is connected to Jane Doe where Jane Doe has the role of Referral.  From our SQL/Fetch XML example, if we wanted to retrieve only related referral records we would set the Record2RoleId to the Referral Id of the connection role.

At PowerObjects, CRM education is one of the four building block to CRM success. Please comment and let us know if this post has been helpful. If you have other topic areas you would like us to focus on in future posts, let us know as well.

Happy CRM’ing

CRM custom reports - Issues with pre-filtering and non-searchable primary key for an entity.

We're gonna get a bit technical today.

In Microsoft Dynamics CRM, one of the reasons for turning on pre-filtering for custom reporting is to associate the report with the open form (record) so that it picks up the unique identifier of the opened record and passes it to the report. So, when the report is run, it filters records and only displays information about the opened record.

The following is the FetchXML report definition code snippet for turning on pre-filtering (for entity Cases- a.k.a. incident):

<entity name="incident" enableprefiltering="true" prefilterparametername="FilteredIncident">

CRM Team

When running a custom report, if you are getting following message that prevents the report being rendered- follow the instructions below.

It can take you some time to figure out the issue like this.

As per the message above, the pre-filtering tried to use the primary key field of the entity to pull the record. But the field – in this case incidentid was not found because it was not searchable. Pre-filtering uses the advice find to look for the record. In this case, the incidentid was not searchable and pre-filtering did not find that field and hence the error.


Make the field searchable by going to Settings->Customizations->Customize the system->Cases (primary entity the report is for) and open the field and make it searchable and publish customizations.

Everything should work as expected!

Hope this will save some time if you are experiencing the above issue. If you have any custom reporting needs or issues please reach out to our CRM team at PowerObjects.

Happy CRMing!

Filtered Lookups in Microsoft Dynamics CRM 2011

Filtered lookups was an oft asked for feature in the yesteryears of Microsoft Dynamics CRM 3.0 and CRM 4.0 with a variety of solutions being offered and implemented to tackle it – all of course were unsupported. With Microsoft Dynamics CRM 2011, the guilty pleasure of custom hacking an unsupported solution to achieve filtered lookups and bragging about it has been denied by Microsoft. So instead I will blog about the out of box solution for filtered lookups in Microsoft Dynamics CRM.

Let's take an example and work through it – suppose you want to have a relationship on the contact record that specifies the preferred shipping partner. But you also do not want all accounts to be displayed in the lookup which includes all types of accounts – in other words, you want the "Preferred Shipping Partner" field to be a filtered lookup to Accounts that displays only the accounts which have an account type of "Shipping".

It all starts in the customization section under the setting area of CRM 2011. This is what you need to do:

Let take a little closer look at the options available in the 'Additional Properties' section:

What other features in CRM 2011 would you like to get a more in-depth look at from the CRM Experts at PowerObjects?

Happy CRM'ing!

All About Filtering Views in Dynamics CRM 2011

Let's say you need to quickly filter data so you can turn your View into something actionable. How would you do it? Filtering views in Dynamics CRM 2011 can help you decide which companies to include in your next marketing campaign.

Sometimes rather than creating a new advanced find, it's more efficient and productive to simply filter a view that already exists.

In this example we'll use the Active Accounts View, but you can do this with any View. From within the Active Accounts View we first select the Filter icon from the Ribbon. Notice the arrows that appear to the right of each column after clicking the filter icon.

These are what we will use for filtering.

Suppose you are thinking about planning a new marketing campaign so you only want to see Accounts that are classified as Prospects. To do this you'll want to add a filter so you only view Accounts with a Relationship Type of Prospect. Select the arrow next to Relationship Type and check the box for Prospect and click OK.

Now when we look at the Active Accounts View we only see Accounts with a relationship type of Prospect. But we can tell it's a filtered by Relationship Type because of the filter icon next to Relationship Type.

Summary Filtering within a view in Microsoft Dynamics CRM 2011 is an efficient and easy way to get a different view of our data and quickly make our data actionable.

Happy CRM'ing!

CRM 2011 – Filtering your Views – Without the Advanced Find

We all know the Power of the Advanced Find tool in Microsoft Dynamics CRM, but in CRM 2011, not only is the Advanced Find functionality enhanced… "Excel Like" filtering is available from within the grid!

This new functionality is available from both the CRM 2011 Outlook Client and the CRM 2011 Web Client.

From within any view, click the "Filter" button

Once the filtering has been turned on, you will notice column headers change.



Clicking on the dropdown arrow allows you to filter based on a few "pre-defined" criteria, or create a "custom" filter on the fly!

The "Custom Filter…" option allows you to select up to two possible filter criteria (For that column) using similar operators found in the Advanced Find tool. (Equals, Does Not Equal, Contains Data..etc..)

Once you have added filter criteria to the column, the icon will change. When you hover over the filter with your mouse it will reveal the filter criteria that you chose.

You can create custom filters for each Column in the view if you would like

If you would like to save this view for future use, at the top of the screen, click the view tab and choose

"Save As". This will allow you to save the view, the same way that you would in the Advanced Find tool.

Add this new Filtering functionality to an already powerful Advanced Find tool, and you have an easy to use Query / Ad-Hoc Reporting tool that is easy to learn for all levels of CRM users.

Thanks for spending a little time with PowerObjects today – the Microsoft Dynamics CRM Experts – as always we would love to work with you and take your MSCRM experience to a new level!

Happy CRM’ing

Microsoft Dynamics CRM 2011 Filtered Lookups

In CRM 4.0, creating a "Filtered Lookup" was… well… kind of a pain. It required quite a bit of JavaScript on the Form in order for the filter to work correctly and if you needed to make additional modifications later on… You get the picture! Good CRM 2011 filtered lookups are simple, and you don't have to know JavaScript to create them.

Example 1: I would like the "Out of the box" Primary Contact lookup on the Account, to ONLY show the contacts that are related to that particular Account. (Very Common request)

Step 1: Access the Account form (From your Solution or Main Customization Area)

CRM 2011 filtered lookups

Step 2: Open the Form and "Double Click" the Primary Contact field to access the Attribute Properties, then scroll to the bottom of the Field Properties window to adjust the properties of the Lookup!

In addition to being able to filter on Related Records, you can create Filtered views and have the Lookup use it as the default!

Example 2: In CRM, I have multiple "Account Types". The Account Type field is a Picklist (Option Set) with the following choices: Hospital and Surgery Center. I would like to add an additional Lookup field on the Account form that looks up all Accounts with the "Account Type" of "Surgery Center".

Step 1: Create the View that filters all Accounts where the Account Type = Surgery Center

Step 2: Create a new Lookup field on the Account Form. (Account to Account)

  1. Access the Account form (Customization Area)
  2. New to CRM 2011 – Create the Lookup directly from the Form!
    -- At the bottom of the Account form, click "New" to create a new Field.

  3. Add your display name and choose the Field "Type" of Lookup.

  4. After the field has been created, add the field to the form using the new "Drag and Drop" functionality.

  5. Double click the field to open its properties

  6. Change the "Default View" to your new View!

As always, make sure to publish your changes to make them available to the users! And that's how you use CRM 2011 filtered lookups.

Hope you find this helpful – and don't be afraid to reach out to the Microsoft Dynamics CRM experts at PowerObjects!

Happy CRM'ing

Relevance Search – Additional Filtering Using Facets and Filters

Relevance Search distributes a search in a single result list and sorts it by relevance based on a scoring concept. One key thing to know is that the higher the score, the more relevant the item.

Relevance Search can:

• Find matches to any word in the search phrase. Matches include various forms of the search word for example, "service," will match to "servicing," or "serviced"

• Search for text in emails and notes

• Search records that you own as well as those that have been shared with you

• Search for text in an Option Set and Lookup field

• Search for text in SharePoint integrated documents (scheduled to be included in the next Dynamics 365 update)

• Search for text within Documents in Dynamics 365. These include documents in a Note, Attachments, Email, and Appointments.

As you can see, the Relevance Search can do many great things but it can also result in millions of matches depending on the size of your organization. Luckily, for us, Microsoft has thought about that and included a feature called Facets and Filters. We get additional filtering by Record Type, Owner, Modified Date, and Created Date to personalize search experience.

Additional Filtering using Facets and Filters

Global Facets: You can refine your search results to Record Type, Owner, Created On, or Modified On. In this example below, I filtered the search results to only show records for a specific "Owner."

relevance search

Entity Specific Facets: When you click on a specific record type, additional facets appear. These facets are specific to the fields of the Record Type/Entity. System Administrators and System Customizers can configure which fields are available for faceting through the entity's Quick Find view. In the example, clicking on Cases gave me two additional facets: Priority and Origin.

relevance search

End user configuration: End users can also personalize their search experience by configuring the facet fields that they would like to see for any searchable entity.

relevance search

relevance search

Now that you have learned how to narrow your search results you will get results that are more relevant to your needs, making it easier to find what you are looking for.

Keep up with the latest and greatest on Dynamics 365 by subscribing to our blog here!

Happy Dynamics 365'ing!

The Social Pane: Filtering Activities in CRM 2016

In Dynamics CRM 2016 there is a little known enhancement to the activity controls on the Social Pane that gives users the ability to filter on various activity types. In today's blog, we'll be focusing in that new enhancement, but first, if you haven't already, check out our previous blog, Surfacing Activities on Records in Dynamics CRM: The Social Pane vs. Sub-Grids.

When you navigate to any record with the Social Pane and click on the Activities tab, you will see the new filter icon before "See the records associated with this view." When you click on the filter icon, you can filter on specific activity types or view all. This gives you a view of the exact activity types you're looking for rather than a mix of everything.

Here are a few examples:

Social Pane

Social Pane

Want to learn more? Check out The CRM Book, a free online resource for anything and everything related to Dynamics CRM. You can find tips for working more with the Social Pane in CRM!

Happy CRM'ing!