Bing Search The Wiki (Example Extension Project)

I took some run-up and showed a couple of things within the last blog posts I want to bring together now for a small example how you can build an small but useful extension to the new Microsoft Dynamics AX. Amongst others, there were examples for event subscriptions, project export/import, how to use the Browser class, create an extension package and a way to search the Wiki cleverly. Today I want to combine all of that into a simple solution that uses extending techniques only and adds the ability to search the Wiki via Bing directly from AX.

The Design

The solution should integrate the Wiki and since there is an integration of it already I planned to use and extend the SysHelpPane form (which can be opened by clicking the question mark symbol in the upper right). The result looks like the following:

Bing Search The Wiki SysHelpPane Extended

First I tried to achieve an integration of the existing search filter field (which is a QuickFilterControl) but failed because I couldn’t force it to provide it’s value without the user applying the filter value by clicking on the search symbol. Plus all that is triggered after the user starts the search from this control is private and invisible for extensions. And so I chose to go for separate controls, an additional tab with a string search field and a button to start the search.

The Solution

The solution contains all the objects in a newly created package axilityBingSearchTheWiki that is an extension package to Application Foundation (because the help stuff is in foundation). It consists of an extension to form SysHelpPane, an event handler class for handling of the click on the button and a helper class that encapsulates the logic for creation and opening of the needed URL targeting Bing. There is also a separate label file for this package / solution.

Bing Search The Wiki Solution

Form extension

I gave it the name SysHelpPane.xltyExtension so it doesn’t (name-) conflict with extensions of others. The search term string control needs to be set to Auto Declaration = Yes so it can be accessed by the button’s OnClicked event.

Bing Search The Wiki SysHelpPane.xltyExtension

Event Handler Class

I named this class SysHelpPaneXltyEventHandler so it contains my typical prefix but also aligns fine with possible other SysHelpPane* objects in Application Explorer.

class SysHelpPaneXltyEventHandler
{
    /// <summary>
    ///     An OnClicked implementation for our extending button
    /// </summary>
    /// <param name="sender">
    ///     The button is the sender.
    /// </param>
    /// <param name="e">
    ///     There are event arguments but we don't need them here.
    /// </param>
    [FormControlEventHandler(formControlStr(SysHelpPane, xltyBingSearchTheWikiButton), FormControlEventType::Clicked)]
    public static void xltyBingSearchTheWikiButton_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        FormStringControl searchTermControl = sender.formRun().design().controlName(formControlStr(SysHelpPane, xltyBingSearchTheWikiSearchTerm));
        str filterString = searchTermControl.text();
        xltyBingSearchTheWikiHelper helper = new xltyBingSearchTheWikiHelper();
        helper.openInNewTab(filterString);
    }
 
}

Helper Class

class xltyBingSearchTheWikiHelper
{
    /// <summary>
    ///     This method opens a new browser tab navigating to the AX Wiki using the search term provided.
    /// </summary>
    /// <param name = "_searchTerm">
    ///     The search term as string. It may include blanks.
    /// </param>
    public void openInNewTab(str _searchTerm)
    {
        Browser browser = new Browser();
        browser.navigate(this.getBingSearchAxWikiURL(_searchTerm), true, false);
    }
 
    /// <summary>
    ///     Prepares and returns a valid URL for a Bing search.
    /// </summary>
    /// <param name = "_searchTerm">
    ///     The search term as string.
    /// </param>
    /// <returns>
    ///     A valid Bing search URL.
    /// </returns>
    public str getBingSearchAxWikiURL(str _searchTerm)
    {
        return 'http://www.bing.com/search?q=' + this.getPreparedFilterString(_searchTerm) + '+site%3Ahttps%3A%2F%2Fax.help.dynamics.com%2F';
    }
 
    /// <summary>
    ///     We take it easy and only handle blanks and replace them by plus signs.
    /// </summary>
    /// <param name = "raw">
    ///     The unformatted input filter string.
    /// </param>
    /// <returns>
    ///     A formatted filter string prepared for being searched for on Bing.
    /// </returns>
    private str getPreparedFilterString(str raw)
    {
        return strReplace(strLRTrim(raw), ' ', '+');
    }
 
}

Label File

For the sake of completeness a look at the label file.

Bing Search The Wiki Label File

How It’s Used

Simply open help, switch to the tab BING, put in a search term and click the button. A new tab in your browser is opened and shows the results of a search on Bing limited to the AX Help Wiki.

Bing Search The Wiki Bing Search Results

Btw: The commercial on the right is in German and for real human hair extensions šŸ˜€

What’s The Coolest Thing About This?

Besides it’s usefulness I want to point out that this really is an extension. For adding functionality to an existing part of AX I did not need to modify anything. Future upgrades of AX are most likely to not conflict with this implementation – only the form extension could break if the parent control of the added tab page disappears…

Where Can I Find The Download?

Of course on the dedicated download page.

Leave a Comment