Account Search based on account name through a ribbon button on account grid in CRM 2011


Just created a simple managed solution that will show a button on Account’s grid. It will only get enabled when only one record is selected in grid otherwise it would remain disabled.

For that we can use SelectionCountRule in our EnableRule definition.

On click of button we are calling a JavaScript function and passing guid of the record selected using CrmParameter as the part of JavaScriptFunction Action.

The JavaScript function uses that guid, makes a OData call and retrieves the account name and passes that account name as a query parameter to google search url and uses method to open the page.

RibbonDiffXml for that:-

          <CustomAction Id="MyOrg.CustomAction" Location="Mscrm.HomepageGrid.account.MainTab.Collaborate.Controls._children" Sequence="1">
              <Button Id="MyOrg.Button" ToolTipTitle="Search in Google" ToolTipDescription="Search detail of the account selected" Command="MyOrg.Command" Sequence="1" LabelText="Search in Google" Alt="Search in Google" Image16by16="$webresource:new_search16" Image32by32="$webresource:new_search32" TemplateAlias="o1" />
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
          <CommandDefinition Id="MyOrg.Command">
              <EnableRule Id="MyOrg.EnableRule"></EnableRule>
            <DisplayRules />
              <JavaScriptFunction Library="$webresource:new_search" FunctionName="search">
                <StringParameter Value="Guid Selected"></StringParameter>
                <CrmParameter Value="SelectedControlSelectedItemIds"></CrmParameter>
          <TabDisplayRules />
          <DisplayRules />
            <EnableRule Id="MyOrg.EnableRule">
              <SelectionCountRule AppliesTo="SelectedEntity" Maximum="1" Minimum="1"></SelectionCountRule>
        <LocLabels />


function search(message,value)
var  Id = value;
var serverUrl = Xrm.Page.context.getServerUrl();
var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

var retrieveAccountReq = new XMLHttpRequest();"GET", ODataPath + "/AccountSet(guid'" + Id + "')", false);
retrieveAccountReq.setRequestHeader("Accept", "application/json");
retrieveAccountReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");

retrieveAccountReq.onreadystatechange = function () {


function retrieveAccountReqCallBack(retrieveAccountReq) {

  if (retrieveAccountReq.readyState == 4) {
  if (retrieveAccountReq.status == 200) {

 var accountName = eval('('+retrieveAccountReq.responseText+')').d.Name;""+accountName);
  else {
     alert("Call Failed.");

The managed solution:-

Just change the extension to zip from doc.

Hope it helps!



Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

4 thoughts on “Account Search based on account name through a ribbon button on account grid in CRM 2011”

Please share your thoughts

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.