Dynamics-CRM

How to display only active records in MS CRM 4.0 extended search lookup

Posted on

While working at one of our projects our customer gave me a task to display only active records (in this particular case this was services ) in extended search lookup. The solution appeared to be very simple, but I spent some time before coming to it. Hopefully, this will save someone’s time too.

First I tried to change the exported entity customization file manually adding a filter:

<filter type=”and”>

<condition attribute=”statecode” operator=”eq” value=”0″ />

</filter>

And while importing it back I did not achieve necessary result. The n I decided to write a simple plugin which would replace a generated fetch xml to the ‘right’ one. Here is the plugin code:

public void Execute (IPluginExecutionContext context)
{
if (context.InputParameters.Contains («FetchXml»))
{
string FetchXml = (String) context.InputParameters[“FetchXml”];
//checking that I am working with product
if (FetchXml.Contains («<entity name=\»product\”>”))
{
//replacing to a necessary fetch xml
context.InputParameters[“FetchXml”] = «<fetch version=\»1.0\”
}
}

Then you need to register the plugin:

picture1

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>