joi, 4 februarie 2010

How to filter the lookup list

2 stepts must be done for this:

1.On the server side make the following changes in "_controls\looku\lookupsingle.aspx":

add this at the top of the page

<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)



{


if( Request["search"] + "" != "" && Request["browse"] + "" == "1" )



{


crmGrid.AddParameter("fetchxml", Request["search"] );


crmGrid.Parameters.Remove("searchvalue");


}



}


</script>

2. In the form add at onload event something like this (is just a particular example):

var field = crmForm.all.new_party1; // the new_party1 is in fact the lookup field

// Ensure that search box is not visible in a lookup dialog
field.lookupbrowse = 1;
// Support New Button
field.AddParam("parentId",crmForm.ObjectId);
field.AddParam("parentType",crmForm.ObjectTypeCode);

// Here you define the search parameters
var fetchStr = ""
+ "
"

// you can add when you need multiple conditions

// Pass fetch xml through search value parameter
field.additionalparams = "search=" + fetchStr;