Comparison of the CRM 2011 and CRM 2013 Filter Functionality

Home  /  Solutions and Services  /  Microsoft Dynamics CRM  /  Comparison of the CRM 2011 and CRM 2013 Filter Functionality

MS Dyn prefilter One of the differences between the CRM 2011 and CRM 2013 systems is how you can filter views. In 2013, new functionality was brought in that allows you to pre-filter from the columns currently existing in default view. This works really well when you don’t have a complex query from which to gather data from.

If your fetch XML includes a link entity it will not work because you can’t filter from columns that aren’t in the view yet.

The solution for this or if you have a complex fetch query and you use the 2011 version. This version allows you to gather data from multiple tables and return it to one custom view.  You are also able to set this custom view as the default view.

And if one were so inclined, they could set the custom view as default and then do the custom pre-filter search from that.

For a project we were working on, we had a field that was of type account look up and our customer wanted to populate that view with alternate bill-to accounts for the customer on the form.

Because this query involves two link entities, we weren’t able to use the 2013 version because we were trying to filter a column that wasn’t yet in the view.
Also, given the complex nature of the fetch query we weren’t able to create a system view from which to filter off of.

So we used a solution introduced in 2011, by which we wrote the fetch query, the layout XML and added that as a custom view to the look up field.

Now when you do the lookup, the results are filtered by every account listed as alternative bill to account for the customer.

Here is the code you will need: 

function preFilterLookup() {
var potentialCustomer = Xrm.Page.getAttribute("customerid").getValue();
if (potentialCustomer != null) {
var accountId = potentialCustomer[0].id;
var name = potentialCustomer[0].name;
createViewForBilling(accountId, name);
function createViewForBilling(accountid, accountname)
var _viewId = '{20CBCCF3-AC63-46FE-920B-DFEF53BCDE32}';
var _entityName = 'account';
var _viewDisplayName = 'Alternate Bill To Accounts : ' + accountname;
var fetchXML ="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
"<entity name='account'>"+
"<attribute name='name' />"+
"<attribute name='primarycontactid' />"+
"<attribute name='address2_line1' />"+
"<attribute name='address2_city' />"+
"<attribute name='address2_postalcode' />"+
"<attribute name='address2_stateorprovince' />"+
"<attribute name='address2_county' />"+
"<attribute name='address2_country' />"+
"<order attribute='name' descending='false' />" +
"<link-entity name='connection' from='record2id' to='accountid' alias='ah'> " +
"<filter type='and'>"+
"<condition attribute='record2roleid' operator='eq' uiname='Alternate Bill-To' uitype='connectionrole' value='{0F962F93-DDB5-E311-8FAC-6C3BE5A8C238}' />" +
"<link-entity name='account' from='accountid' to='record1id' alias='ai'>"+
"<filter type='and'>"+
"<condition attribute='name' operator='like' value='"+accountname+"' />"+
"</entity>" +
var layoutXML = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
"<row name='result' id='accountid'>" +
"<cell name='name' width='150' />" +
"<cell name='primarycontactid' width='150' />" +
"<cell name='address2_line1' width='150' />" +
"<cell name='address2_city' width='150' />"+
"<cell name='address2_postalcode' width='100' />" +
"<cell name='address2_stateorprovince' width='100' />" +
"<cell name='address2_county' width='100' />" +
"<cell name='address2_country' width='100' />"+
"</row>" +
var lookupControl = Xrm.Page.ui.controls.get('new_billto');
//in this call, true sets the custom view to the default view.
lookupControl.addCustomView(_viewId, _entityName, _viewDisplayName, fetchXML, layoutXML, true);


3 Comments so far:

  1. […] Comparison of the CRM 2011 and CRM 2013 Filter Functionality […]

  2. […] Comparison of the CRM 2011 and CRM 2013 Filter Functionality […]

Leave a Reply

Your email address will not be published. Required fields are marked *