Web Resources Customization

The eResources menu that can be accessed on the Account and Contact edit screens in Microsoft CRM is a great way to get contextual information from an external Web site based on the current record displayed. For example, these options can be used to get a list of restaurants near a customer's place of business or look at the weather in the customer's part of the world. However, there are only five resources available, new links cannot be added or removed, and the destinations of the existing links can't be changed.

NOTE

All but one of the default links on the Web Resources menu redirect the user to a Microsoft-owned Web site. The Research Company link refers to Hoovers.


Now, we just said that the destinations of the eResources links cannot be changed, but that is not entirely true. When the user clicks on one of the five links, client-side JavaScript functions are called. Those five JavaScript functions are located in the webResources.js file under the forms folder. This file can be edited to redirect the user to a different Web site, but modifying standard Microsoft CRM files is, of course, not recommended or supported.

Let's look at what can be done, for example, to add a Web search engine link on the Lead edit screen. This link could be used to find out if the Lead has ever been mentioned in the press or has ever published articles. Another example is a link on the Account edit screen to a financial Web site such as Yahoo finance to get the company's current stock price.

Our solution to this problem involves creating additional menus in the CRM application, creating an ASPX page, and doing a little bit of C# (pronounced C sharp) programming. Conceptually, what we're going to do is create one Web page that gathers the information about the record currently on the screen, fetch additional data out of the CRM system, and forward the appropriate values to an external Web site.

Here are the steps to implement this solution:

1.
Create a “Web Resources” menu

Edit the isv.config file to add the new menu. Paste the following under the Account entity:

<MenuBar>
<CustomMenus>
<Menu Title="Web Resources" ValidForCreate="0" ValidForUpdate="1">
<MenuItem Title="Stock Price" Url="/Custom/WebResources.aspx?resource=StockPrice"
PassParams="1" WinMode="0"/>
</Menu>
</CustomMenus>
</MenuBar>

also paste the following under the lead entity:

<MenuBar>
<CustomMenus>
<Menu Title="Web Resources" ValidForCreate="0" ValidForUpdate="1">
<MenuItem Title="Research" Url="/Custom/WebResources.aspx?resource=Research" PassParams="1" 
WinMode="0"/>
</Menu>
</CustomMenus>
</MenuBar>

Notice that both of our menu items are pointing to WebResources.aspx which is a custom page we will create shortly. This page gathers the information about the Account or the Lead record and redirects the user to a page on an external Web site.

Notice also that the PassParams attribute is set to 1. This flag tells the CRM platform to pass the record's unique identifier to our custom page. This is important because we will use this information to retrieve more data about the record and pass that data to the external site.

2.
Create the WebResource.aspx Web page

Save the attached file in the Custom folder under C:InetPubwwwroot on the Microsoft CRM Web server.

We will not go into detail about the C# code in the ASPX page because some of the concepts are discussed in more details in the Microsoft CRM SDK section of this chapter. That code is divided into the following sections:

  1. Variable setup. This is where we set the server name, virtual directory where the Web services are published, and so on.

  2. Parse the querystring to retrieve the contextual object unique identifier and object type.

  3. Prepare and run a query using fetchXML to return detailed information about the object. A detailed discussion of FetchXML is beyond the scope of this chapter and this book, but we strongly encourage you to read up on it on MSDN as this is a very powerful query language for Microsoft CRM. Similar to the TransactSQL language for Microsoft SQL databases, FetchXML enables you to build complex queries and extract records out of your CRM database via the Microsoft CRM API.

  4. Redirect the user to an external Web site with the necessary contextual information such as the name or the stock symbol.

The necessary files to re-create this customization can be found under the Chapter 14 examples folder on the companion CD-ROM. Figure 14.2 shows a Contact record with our Web Resources menu implemented.

Figure 14.2. Creating a custom Web Resources menu to call a Web site and pass information about the active CRM object.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.104.175