Comment unsuccessful. Please correct the errors below.

Filtering lookup data in CRM 4

Now we all know that when Microsoft says "unsupported" they always sometimes mean business. Take, for example, popular CRM 3 customisation to filter lookup field data that used to work well. Until version 4, that is. Not all is lost, however, because no thanks to me but to Adi Katz, now there is new unsupported way to make it work in CRM 4 as well.

For example, to make primary contact lookup for an account record to show contacts from this account only, the following customizations are required:

[more]

Form OnLoad script

The script looks almost identical to the original one except for one very important change. We have to pass fetch xml string using one of the parameters recognised by the server otherwise exception is thrown (there is a way to disable parameters check through the registry setting DisableParameterFilter, but it's easier without yet another undocumented setting). Since we want to disable search functionality it makes sense to re-use search parameter.


var field = crmForm.all.primarycontactid;
if(crmForm.ObjectId == null)
{
    // Disable lookup for new account record as there can be no contacts
    field.Disabled = true;
}
else
{
    // Ensure that search box is not visible in a lookup dialog
    field.lookupbrowse = 1;
   
    // Pass fetch xml through search value parameter
    field.AddParam("search",
     "<fetch mapping='logical'><entity name='contact'>"
    + "<filter><condition attribute='parentcustomerid' operator='eq' value='"
    + crmForm.ObjectId
    + "' /></filter></entity></fetch>");
}

Field properties

If automatic resolution for the field is enabled and user types something in the field, it causes direct web service call that would ignore our fetch xml. In other words, user would be able to set the field value to any of the contacts in the database by simply typing contact's name. Disabling automatic resolution solves the issue:

Field properties dialog

Lookup dialog

Turns out, grid control in version 4 still recognises fetch xml, the challenge was to pass it. Kudos to Adi for finding a very clever workaround to inject fetch xml directly. The following code needs to be inserted anywhere in the <CRM site folder>\_controls\lookup\lookupsingle.aspx file.


<script runat="server">

protected override void OnLoad( EventArgs e )
{
      base.OnLoad(e);
      crmGrid.PreRender += new EventHandler( crmgrid_PreRender );
}

void crmgrid_PreRender( object sender , EventArgs e )
{
    // As we don't want to break any other lookups, ensure that we use workaround only if
    // search parameter set to fetch xml.
    if (crmGrid.Parameters["search"] != null && crmGrid.Parameters["search"].StartsWith("<fetch"))
    {
        crmGrid.Parameters.Add("fetchxml", crmGrid.Parameters["search"]); 

        // searchvalue needs to be removed as it's typically set to a wildcard '*'
        crmGrid.Parameters.Remove("searchvalue"); 

        // Icing on a cake - ensure that user cannot create new contact outside of the account
        // and then select it.
        this._showNewButton = false;
    }
}

</script>

 

You are on your own

I cannot stress enough that this customisation is 100% unsupported so use it at your own peril. In particular, because server files were modified, there is a good chance that you'll see yellow screen of death on a regular basis (if you've switched DevErrors on, that is). Much easier, supported way to achieve the same functionality (and much more) is to use custom lookup dialog from Michael Höhne.

Happy hacking!

Posted by: George Doubinski
Last revised: 05 Dec, 2012 05:26 PM

Comments

nike40
nike40
28 May, 2014 11:33 AM

Thank you so much for putting up a very good comparison on CRM3 version and the latest one. The users will not be much used with the latest version so I think the codes and algorithms here will be helpful for all. Good post fashion for play

Tony
Tony
17 Jul, 2014 01:33 PM

I'm gonna use this scripts to solve my problems with the updated version. I had just bookmarked this page, as I got a lot of useful information from this page. Thanks. Regards, [apple.com][1]

[1]: apple.com

antonubanderas
antonubanderas
18 Aug, 2014 07:47 AM

I am so glad to see the great tribute here. So much good has come from her great work. So many looked up to here so much. Glad this was offered. whiterock real estate

Jonah
Jonah
06 Sep, 2014 12:35 PM

I've faced a few issues through updating my CRM data and I've been searching for the perfect solutions since ages. But the above article had resolved my problems and I'm glad that I could make it up. Thanks for the share. Regards, ghost writer

11 Mar, 2015 03:02 PM

I've faced a few issues through updating my CRM data and I've been searching for the perfect solutions since ages. But the above article had resolved my problems and I'm glad that I could make it up. Thanks for the share. Regards, ghost writer

David Gibbson
David Gibbson
31 Mar, 2016 04:35 AM

The tips and tricks that are shared here on the page to filer the lookup data proved to be an interesting one. I am doing my higher studies on data mining and the post helped me a lot. Keep up the good work guys!

hotels on catalina island

Bloggy
Bloggy
25 Apr, 2016 03:48 AM

I am a computer science student and this site has helped me a lot to make a good idea on the various CRM details and technical details on the same. Keep on sharing more and more posts like this. Thank you for sharing cryotherapy

danette
danette
14 Jun, 2017 12:09 PM

This post clearly specifies the Filtering look up data in CRM4. I think they have specified all in detail with specific examples. Starting with onload scripts and then going through all the field properties. Anybody can understand this concept very clearly through this article. beverly diamonds complaint

albert
albert
15 Aug, 2017 09:18 AM

Amazing stuff! I really like the information of this post. This post contains a lot of interesting material which i like the most. water damage orlando florida

Harry
Harry
24 Aug, 2017 12:02 PM

I am very happy to see your data because is very useful for us. I went over this website and I believe you have a lot of wonderful information. custom box packaging design

aaa
aaa
03 Nov, 2017 10:32 AM

Natural Hair Dyes

Dimons
Dimons
03 Nov, 2017 10:46 AM

The information given is accurate and knowledgeable. keep it up. I have visited this website first time and I feel it useful. Natural Hair Dyes

dresh
dresh
03 Nov, 2017 10:48 AM

No doubt the information is exceptional and really useful. I cant't stop reading the above information. Beauty Products

01 Jan, 2018 10:14 AM

Kilt Master is the Ultimate Scottish Clothing and Accessories Shop that offer an Extensive Collection of High Quality Kilts, Sporrans, Bagpipes, Flutes, Practice Chanter, Prince Charlie Jackets, Argyle Jackets, Ghillie Shirts, Belts Buckles, and Scottish accessories. https://kiltmaster.com/

Kilt Master has earned a distinct reputation in manufacturing and retailing of custom hand stitched Kilts. We have more than 10 tailors and all the Kilts we have online are custom-made by us with special personal attention given to each piece. This is the main difference between us and cheep mass production units.

Placing an order with Kilt Master means that you get the custom made Kilt directly from the manufacturer, No Agent, No middleman between the tailors and buyers, your special requirements are passed directly to the Kilt Tailor / stitchers.

With loads of eternal appeal and versatility, KiltMaster has always been adaptable and inspirational. The look of the Kilt is timeless; one can make a bold fashion statement and a wise investment at the same time. So if you are willing to make a fashion statement or a dashing entrance, just do it with only of its kind outfit-courtesy at KiltMaster.com.

All our Kilts is manufactured by us in our factory with great care, to the highest standards of workmanship. Choose from our range of high quality Modern Kilts, Utility Kilts, Tartan Kilts, Fashion Kilts, Camouflage Kilts, Military Camo Kilts, Hybrid Kilts, Leather Kilts, Sport Kilts, Traditional Kilts & Mocker Kilts.

We use high quality Cotton, Tartan, Camouflage and Leather. In our Utility Kilts, Tartan Kilts and Leather Kilts.

https://kiltmaster.com/

Jennifer
Jennifer
21 Jan, 2018 07:47 PM

This is my very first time on this website and the information given here is very well organized and clear. I found it very useful that there are images showing us what the author is referring to. Thank you. [url="http://primesunshine.com/"]CBD Charlotte NC [/url][url="http://primesunshine.com/cbd-products/"]cbd on sale [/url]

 joy
joy
17 May, 2018 04:15 AM

best hotels near me

22 May, 2018 01:00 PM

The role of music in your life, you’ll surely like to play Android Apps game.

Allen
Allen
29 May, 2018 10:14 AM

The script looks almost identical to the original one except for one very important change. MB6-895 braindumps

uzovovuzhui
uzovovuzhui
09 Jun, 2018 04:56 PM

http:/// - .ankor .ankor http:///

oloxodapiqozi
oloxodapiqozi
09 Jun, 2018 06:18 PM

http:/// - .ankor .ankor http:///

voedselzandloper dieet
voedselzandloper dieet
16 Jun, 2018 10:11 PM

Insult to today, when there is a surfeit of anti aging appearance discombobulate products like polthi.cremegoji.nl/online-consultatie/voedselzandloper-dieet.html creams, serums, gels and powders that all holler to be this well-spring of youth. Some work out opta.cremegoji.nl/juist-om-te-doen/herstellen-lederen-autozetels.html their anti aging voodoo toe ingredients that beget a ton of all-out high opinion probe into into fesla.cremegoji.nl/online-consultatie/rede-hot.html and division on how lamina ages to rough them up and some are uninfected hype.

Your Comments

Comment unsuccessful. Please correct the errors below.
Used for your gravatar. Not required. Will not be public.
Posting code? Indent it by four spaces to make it look nice. Learn more about Markdown.

Preview