Custom Advanced Find Button on Dynamics CRM 2013 Forms

Posted: May 19, 2014 in Dynamics CRM 2013, JavaScript

Since CRM 2013 now opens forms in the same browser window as the view, it makes it more difficult to access advanced find, which by default is only available from list views.

In this blog post I will describe how to customize the command bar to add an advanced find button onto all forms in the system, so that advanced find can be launched from anywhere, whether on a view or a form.

First you need to create a solution with the Application Ribbons, and a javascript web resource.

Add the following function into the web resource, which is what will be used to launch the advanced find window:

function openAdvFindCustom(etc) {
    var oUrl = Mscrm.CrmUri.create("")
    oUrl.get_query()["EntityCode"] = etc;

    var oMainUri = Mscrm.CrmUri.create("/main.aspx");
    oMainUri.get_query()["pagetype"] = "advancedfind";
    oMainUri.get_query()["extraqs"] = oUrl.get_queryString();
    openStdWin(oMainUri, "_blank", 900, 600);
}

Next you need to customize the command bar XML. Using the CRM 2013 Ribbon Workbench will make this easier. Edit the solution to export the ApplicationRibbon. This is the global ribbon which will be applied to all entities.

Add a new button onto the Form command bar. I’ve added mine just after the ‘Delete’ button. You can copy the icons, labels, and description from the CRM advanced find button on the home command bar.

Finally you need to create a custom command to open the JavaScript function openAdvFindCustom from the web resource, and pass in the PrimaryEntityTypeCode parameter.

Take a backup of the solution before publishing, just in case something goes wrong so you can roll back. Then hit publish at the top of the ribbon workbench. Once the changes are published, refresh CRM and open a form. You should see the new Advanced Find button, which when clicked will open a new Advanced Find window just like it does from the list view.

Note that this JavaScript is unsupported, and could break with future updates.

If you want a more supported solution, you can call the default advanced find button function directly, which means you don’t need your own web resource and JavaScript. However note that this method won’t open advanced find to the entity you’re on, instead it will always default to the first entity in the list. You will still need to create a custom command, with the Function Name as Mscrm.RibbonActions.openAdvancedFind and the Library as /_static/_common/scripts/RibbonActions.js. For this you don’t need to pass any parameters. I’d say this is still unsupported, but it’s using a CRM function instead of a custom one, so it’s a bit nicer if you don’t mind it not opening the entity you’re on.

Advertisements
Comments
  1. Hosk says:

    you might find this tool useful
    https://crmadvancedfind2013.codeplex.com/

    I did a review of it here

    Great article. Will your advanced find button appear on all records (e.g. account, contact, new custom entities) because I want to do that but at the moment I have only worked out how to get the button to appear on the account entity.

    • Paul says:

      Ah nice, I hadn’t seen that tool. Looks like it doesn’t open advanced find up to the entity you are on though.

      My button shows up on all forms, even custom ones. It gets added to the ApplicationRibbon, then using the ribbon workbench you can add it to the ApplicationRibbon form, which is applied to all entity forms. This is also where CRM puts all the generic buttons like Save, Delete, Activate etc.

      • Hosk says:

        Thanks for replying to the comment

        the advanced find solution puts it on all record forms.

        The functionally you described is what I want to do, I will go through that.

        keep up the good blogging Sir

  2. Hosk says:

    great walk through I was puzzling how to edit the application ribbon for a while and your blog has shown me the way.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s