Filter a lookup view

I have a form with two lookup fields:
The first one is called 'workinggroupid'. The second one is called 'alternateid'. I would like to filter the 'alternateid' lookup by the selected 'workingroupid'.

I've added the following code in the lookupsingle.aspx file:

<script runat="server">
protected override void OnLoad( EventArgs 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 '*'
        // Icing on a cake - ensure that user cannot create new contact outside of the account
        // and then select it.
        this._showNewButton = false;

and in the OnLoad script I've added the following code:

var field = crmForm.all.new_workinggroupid;
if(crmForm.ObjectId == null)
    // Disable lookup for new account record as there can be no contacts
    field.Disabled = true;
    // Ensure that search box is not visible in a lookup dialog
    field.lookupbrowse = 1;
    // Pass fetch xml through search value parameter
     "<fetch mapping='logical'><entity name='MemberOf'>"
    + "<filter><condition attribute='new_workinggroupid' operator='eq' value='"
    + crmForm.all.new_workinggroupid.DataValue[0].id.toString()
    + "' /></filter></entity></fetch>");

And.... does not work. Any idea????
Thanks in advance
Who is Participating?
rakeshAgarwalConnect With a Mentor Commented:
hope you  have remove d this code also

>>>I've added the following code in the lookupsingle.aspx

please go to

Have you checked that blog , have you added column to quick find.


Hi  which version of crm you are using this will not work in crm 4.0 .
In crm 4.0

just search for "filter lookup"

you wil get solution to your answer

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

chonichonAuthor Commented:
CRM 4.0
just check the above link
chonichonAuthor Commented:
I've done the following changes:
In the onload event of the form I've added:

document.FilterLookup = function(source, target)
    if (IsNull(source) || IsNull(target)) { return; }
    var name = IsNull(source.DataValue) ? '' : source.DataValue[0].name;
    target.additionalparams = 'search=' + name;

In the onchange event of the Workinggroup field on the form I've added:
document.FilterLookup(crmForm.all.awx_new_workinggroup, crmForm.all.awx_new_alternateid);

And, does not work.
chonichonAuthor Commented:
Now it works...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.