718 Washington Ave. N. Suite #101
Minneapolis, MN 55401
View map and all Locations

Send us a message

Have you had a chance to check out the new CRM for phones or tablets app yet? If not, check out the CRM 2015 Mobile Apps blog post to get caught up. One of the recurring issues we see come up in projects is when related record filtering is not working in the Mobile client as it did in Web client. You can address this issue by using JavaScript, and in today’s blog we will show you exactly how! Let’s begin!


The objective here is to have one entity lookup drive the filtering of another entity lookup. Fairly common use cases are Account and Contact pairing scenarios. These entities already have a pre-existing parent-child relationship in place, which is required for this configuration. If you place both Account and Contact lookups on the form you want the Contacts to be pre-filtered by their parent Account once the Account is selected. This speeds up the selection of correct Contact record for the selected Account.

As you will see in the screenshots below, selecting lookup records in the mobile app is a very different experience than in the web client. Not having records filtered when needed creates a challenging user experience for your users on the go. That’s not a good thing, so let’s fix it!

The Old Way: Form Configuration Method

We have been using the traditional approach to bring this functionality to users for quite some time over many versions of Dynamic CRM. Nothing wrong with that, however, as this is the recommended approach to enable Related Record Filtering as provided by the form configuration available to everyone today.

When editing the form, select a lookup field property and locate this section:

Related Record Filtering is shown in form field properties. Please note here that “Custom Records” is the name of our Entity on which we have the Account and Contact fields placed for our example. Yours might be Cases or something else specific to your system.

Here is an example of what the configuration looks like in the Web version of CRM:

Related Records Filtering works great here, as expected. The Look Up More Records function has even more features for the web version that can help us filter and find the correct record.

The image below shows what this configuration looks like on the CRM for Tablets app.

On mobile, it is quite a different experience. It displays all contacts instead of just two for A. Datum Corporation. There is no Look Up More Records or any other helpful tools here. You will also notice that the contact records shown are not filtered by A. Datum Corporation. In fact, in this experience, it’s difficult to find the correct contact on this screen. This experience is similar on the new CRM for Phones app.

Is there a no code option?

One of the ways to address this is to include the company as one of the first three fields in the Lookup view of the contact entity so that the company name is shown in the list. This will help visually. Adding company to the find columns in that view will let the user search by typing in the name of the company.

While this method may be clever, it isn’t an intuitive user experience. For example, if you have two companies named ACME HOME FURNISHING DELIVERY LLC and AMCE HOME FURNISHING MANUFACTUING INC, errors can occur when the name is trimmed off or looks too close to the correct company. This method is not perfect, but depending on your configuration, it might be the only reasonable option without resorting to adding some form code.

Adding code to fix the problem.

Different from HTML web resources that are not available on Microsoft CRM mobile apps universally, this does not apply to JavaScript web resource files that are referenced on the form using the Form Properties Script Library feature. This does work on both tablet and new phone apps.

Step 1: Setup the web resource for the code.

1. You will need to know the field names of the Account and Contact lookup fields on your form.

2. Create a new web resource of type Script.

3. Here is the code to use for this new web resource:

Note: Be sure to replace new_accountcontrol and new_contactcontrol with your actual field names used on your Form for your specific Entity.

// JavaScript source code

function addEventHandler() {

// Register our own event for PreSearch event on the Contact lookup field



function addAccountFilter() {

var selectedAccount = Xrm.Page.getAttribute(“new_accountcontrol”).getValue();

if (selectedAccount != null)


// Format Filter XML

var filter = “<filter type=’and’>” +

“<condition attribute=’accountid’ operator=’eq’ value='” + selectedAccount[0].id + “‘/>” +


// Add Filter to Contact lookup control

Xrm.Page.getControl(“new_contactcontrol”).addCustomFilter(filter, “contact”);



4. Remember the name of the web resource for the next step where we will reference this code on the form.

Step 2: Setup the form events to trigger the code.

1. Open the Form configuration for the Form that will be displayed on Mobile clients (usually default entity Form, unless you have more complex role-based design).

2. Open the Form Properties window.

3. Select the web resource we created in Step 1, located in the first tab under Form Libraries.

4. In the Event Handlers section, select Form control and add a new event to the OnLoad to trigger the addEventHandler function in your script. Here is what the completed Form Properties should look like in this step:

Note: Your Form Library name should be the one you created earlier.

5. Don’t forget to also trigger the same addEventHandler function on the OnChange event of your Account field Control lookup. This is in case the user changes their mind and selects a different Account; our Contact filter would then not be stuck on the previous filter incorrectly. Here is what the completed Form Properties should look like in this step:

Note: Your Control name and Library should reflect your system.

6. Save and Publish these changes as you normally would.

7. Open the CRM Mobile Application on your device and be sure to allow it to download the new configuration changes when prompted to do so. If you are not prompted, you will not see any difference, so close the app or restart the device and try again.

Although we have not addressed all scenarios, your system and design requirements might call for different behaviors. Be sure to discuss with your business process owner to test and validate all scenarios.

The End Result in Tablet and Phone Mobile Apps

Now, both the web and mobile app experience will behave as expected – filtering contacts by their parent accounts. Here is a screenshot of the tablet application in action:

And here is an example of a correctly working lookup filtering on the CRM for Phones app:

With Microsoft Dynamics CRM 2015 Online v7.1 and newer, the configuration for mobile is shared between tablet and phone clients but does allow for exceptions at the form level for sections or fields to be set to “not visible” on the phone client selectively. If you do not see what you expect on the phone display, make sure that you are seeing the same form section as the tablet.

NOTE: There is not a work around for the Dynamics CRM for Phones Express app as the Express mobile forms do not offer JavaScript capability for this filtering to work.

Sometimes just a bit of code can go a long way, and today we made our system much easier to use on the go. We are very excited for the new opportunities that the new phone and tablet client cab bring to CRM customers. Stay tuned to the PowerObjects Blog for other helpful tips for your Mobile CRM journey. If you are not sure if you should invest time into the out-of-the-box or custom mobile solutions, check out the FREE Mobile Fit Gap Analysis. This process can help identify any issues or gaps in the product early on. Fill out the request form on our Mobile Solutions page to get started today!

Happy CRM’ing!

Avatar for JoeCRM


Joe CRM is a CRM superhero who runs on pure Microsoft Dynamics CRM adrenaline. As the face of PowerObjects, Joe CRM’s mission is to reveal innovative ways to use Dynamics CRM and bring the application to more businesses and organizations around the world.