Posted by : XRM Consultant Thursday, 12 November 2009

As many Dynamics CRM proffesionals will know, the ability to do filtered lookups on CRM 4.0 has long since escaped many of us. The only answer seems to be, "its coming in CRM 5.0" (is it me or is that the answer to everything?)

Anyway, with thanks to a fellow Dynamics CRM blogger, i have found a way of achieving filtered lookups in CRM 4.0!

In my scenario, i needed this functionality for 2 reasons. Firstly, i have an entity called Assets on which i have a set list of values, product families (i.e. servers, laptops etc) This list is published on my form as a picklist attribute. I also have another entity, IT Products, which houses my list of products. The same list picklist of product families is published on the IT Products form.

Therefore, i wanted to be able to add an Asset, select a product family from my drop down list and when clicking on my lookup to my products, display only those with my chosen product family.

I adapted some code found on another blog to achieve this:

Paste the following into the OnLoad event of the form:


document.FilterLookup = function(source, target)
{
    if (IsNull(source) || IsNull(target)) { return; }

    var name = IsNull(source.DataValue) ? '' : source.SelectedText;

name=encodeURIComponent(name);

    target.additionalparams = 'search=' + name;
}

document.FilterLookup(crmForm.all.citja_productfamily, crmForm.all.citja_itproductid);


Paste the following into the OnChange event of the Picklist:

document.FilterLookup(crmForm.all.citja_productfamily, crmForm.all.citja_itproductid);

For those of you that noticed, the "name=encodeURIComponent(name);" line allows you to deal with ampersand characters as well as any other funny international characters that may appear in your list

This works very very nicely and is a great workaround till version 5.

Enjoy

Joel

P.S. Credit to the guys at Advantage Works for their original post

{ 2 comments... read them below or Comment }

  1. Really infomational and educative article thanks publisher for sharing this wonderful info i have shared this article on my blog tecktak flippzilla
    and whatsaup, and Best smart tv

    ReplyDelete

Search This Blog

Popular Post

About xRM Consultant.com

Having worked with Microsoft Dynamics CRM 4.0 in a sales & development environment, my focus now is on customising this awesome solution and showing its true potential.
Powered by Blogger.

- Copyright © xRM Consultant -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -