Skip to main content

Notifications

Tip #274: Lookup fields in CRM for tablets

Community Member Profile Picture Community Member Microsoft Employee

I recently wrote the book The CRM Mobile Survival Guide. In Chapter 5 I discuss how to configure Dynamics CRM to give users a good user experience when using CRM via the CRM for Tablets app.

One thing I found while researching the book is that lookup field behavior in the tablet app is not consistent with other CRM user interfaces, like browser. if you configure field properties to filter a lookup field in form customization, the field will be filtered when using CRM in browser, but the filter will not apply when using CRM via tablet app.

To filter lookup fields in the tablet app, use a JavaScript Xrm.Page.getControl.addPreSearch function.

For example, say I have a custom Account lookup field called “Vendor” (new_vendorid), and I want to filter the lookup to Accounts where relationship type contains “Vendor.”

First, do an advanced find for accounts with the desired filter. The columns displayed in the advanced find don’t matter.

IMG1

Click the “Download Fetch XML” button to download the fetch query. Copy the contents of the Fetch XML between the <filter> tags.

IMG2

Paste the copied filter to the XML editor of your choice, and replace all double quotes with single quotes.

IMG3

Then add the filter to an addPreSearch function on load. This will override the filter of the lookup field with your new filter.

Xrm.Page.getControl(‘new_vendorid’).addPreSearch(function () {

Xrm.Page.getControl(‘new_vendorid’).addCustomFilter(“<filter><conditionattribute=’customertypecodename’operator=’like’value=’%Vendor%’ /></filter>”);

});

Now when you click on the lookup field in the tablet app, the results will be filtered based on the custom filter in your PreSearch function.

Bonus double dip

Since writing the Mobile book, I have discovered another inconsistency with lookup fields on the tablet app–they only search against the primary field. If you have other fields defined as find fields, from browser you can type in the field find the record using another search attribute. From the tablet app, the lookup field will only search the primary (name) field of the lookup entity.

Comments

*This post is locked for comments