Creating a Custom Search Button


CRM MVP Mitch Milam returns as a guest blogger. You can read more from Mitch at his blog.

Occasionally I get a request from a customer to create a custom search screen that will allow them to perform specific queries that they use on a frequent basis. Usually, I point them to the Advanced Find feature and have them save their Advanced Find query as a Saved View. This process works for the majority of customers, but one of my current projects had a requirement to make this type of process a little more user friendly.

Not wishing to reinvent the wheel, I started looking at the Advanced Find and View functionality and created what I think is a fairly elegant solution.

Creating a Custom Search View

Working with the Contact Entity, we start this process by creating a new system view called Date Range Search – Active Contacts, which will look like the following:

clip_image002

Our filter criteria will look like this:

clip_image004

As you can see, we’ve created an AND search using the Created On Attribute looking for a start date that is On or After a specific date AND the end date is On or Before a specific date. This AND grouping will give us the net effect of Between. At this point, the dates entered are not actually relevant to our query. They are merely placeholders since CRM requires us to enter a date before saving the Filter Criteria.

We also check the Status Attribute and make sure that we only return Active records.

After you’ve finished defining the new view, save the view then publish your changes to make them available.

Capturing the Advanced Find URL

Now we need to determine the URL used by CRM to display the filter criteria we used to create the Date Range Search – Active Contacts view. Perform the following steps:

Open the Date Range Search – Active Contacts view:

clip_image006

Click on the Advanced Find button to display the filter criteria for the current view:

clip_image008

We need to capture the URL that is used to display this form. The quickest way to make that happen, is to press Ctrl+N to instruct Internet Explorer to open a new window. It will display like this:

advsearch2

Copy the URL from the address bar then close both of the Advanced Find windows.

The URL captured on my system looks like this:

http://localhost/CRM40/AdvancedFind/AdvFind.aspx?EntityCode=2&QueryId={8AE34E2D-36B6-DC11-A19C-001731B019EA}&ViewType=1039

Modifying the ISV.Config file ( CRM 3.0 )

We’re going to add a button to the Contacts grid that will allow our users to activate the new search feature. This operation is performed by editing the isv.config.xml file found in the folder:

[crm website]\_Resources

Locate the Entities section, located toward the bottom of the file and replace this code:

<Entity name="contact" />

With the following code:

<Entity name="contact">

<Grid>

<MenuBar>

<Buttons>

<ToolBarSpacer />

<Button

Title="Date Range Search"

Client="Web, Outlook"

ToolTip="Perform a Date Range Search"

Icon="/_imgs/ico_16_4230_d.gif" JavaScript="window.open('/AdvancedFind/AdvFind.aspx?EntityCode=2

&amp;QueryId={8AE34E2D-36B6-DC11-A19C-001731B019EA}

&amp;ViewType=1039');"

/>

</Buttons>

</MenuBar>

</Grid>

</Entity>

The JavaScript statement will open a window containing the URL we captured in the previous step. You need to copy the text in the URL from the question mark ( ? ) to the end of the URL:

EntityCode=2&QueryId={8AE34E2D-36B6-DC11-A19C-001731B019EA}&ViewType=1039

And place it inside the window.open command. This will guarantee that the URL matches the configuration of your system exactly.

Note: You will notice that the ampersands ( & ) found in the URL have been replaced with &amp;. Since the isv.config is an XML file, we need to “encode” them so that the XML parser doesn’t try to “interpret” the ampersand as a command and thereby destroying our URL.

After editing the isv.config file, you’ll need to refresh your browser to make the new customization display. You may also need to delete your temporary Internet files.

Modifying the ISV.Config file ( CRM 4.0 )

The process for CRM 4.0 is very similar to that of CRM 3.0 except for the fact that you need to Export your isv.config file then add replace <Entity name="contact" />

With:

<Entity name="contact">

<Grid>

<MenuBar>

<Buttons>

<Button Client="Web, Outlook" Icon="/_imgs/ico_16_4230_d.gif" JavaScript="window.open('/[orgname]/AdvancedFind/AdvFind.aspx?EntityCode=2&amp;QueryId={8AE34E2D-36B6-DC11-A19C-001731B019EA}&amp;ViewType=1039');">

<Titles>

<Title LCID="1033" Text="Date Range Search"/>

</Titles>

<ToolTips>

<ToolTip LCID="1033" Text="Date Range search for active contacts" />

</ToolTips>

</Button>

</Buttons>

</MenuBar>

</Grid>

</Entity>

Note: You will need to replace “[orgname]” with the name of CRM Organization. This will be especially important in a multi-tenant environment.

After you’ve imported your changes, you’ll need to refresh your browser to make the new customization display. You may also need to delete your temporary Internet files.

Putting Date Range Search to Use

After the customization had been added, you’ll now see a new button on the Contacts grid:

clip_image012

Clicking the Date Range Search button will display the following form:

clip_image014

All the user has to do at this point is to change the start and end dates and click the Find button to execute the search.

While this may not seem to be a huge deal, it does save the user a few seconds ( and a click or two ). If performed several times per day, the savings starts to add up.

Conclusion

This example is uses the Contacts Entity but it can be applied to any standard or custom CRM Entity.

Mitch Milam

Comments (7)

  1. Thanks, but i need to catch link of saveed view then put it on sales area for exp?

    using CRM 3.0?

  2. Eric says:

    We just installed CRM 4.0 and noticed in the workspace (left pane) a custom search button.

    What is the prupose of this custom search?

    Thanks

  3. Leighton says:

    Is there anyway of making this available for "Read-Only" users… all but the Advanced Find button is removed for this user group.

    Thanks for any help.

    L

  4. Sander says:

    Thanks for this Mitch!

    I’ve used your example to create a Contract Line lookup from the case entity.

    Cheers

  5. Sharan says:

    Good one ,some times this help the customer to get teh requird data very easily instead of ending up in creating a report / every time open the advanced find to get this report

  6. JimenezAlberto says:

    I'm trying to do something similar in CRM 2011, but the Advanced Find URL is not working. Can you help me with this?

Skip to main content