Update Selected Records in Home Page entity grid in CRM 2011

Posted: November 29, 2012 in CRM 2011, Ribbons

In one of my requirement i need to update the selected records in the home page contact entity grid by clicking on the custom ribbon button. Below is the code to add a ribbon button in the home page contact entity and update the selected records.

To update the records using OData, you need to add jquery1.4.1.min and json2 files. You can get those files from sdk
path – \sdk\samplecode\js\restendpoint\jqueryrestdataoperations\jqueryrestdataoperations\scripts.

Create a new solution, add the contact entity and export the solution. Open the customizations.xml file and replace the <RibbonDiffXml> with following code.

          <CustomAction Id="Isv.contact.MainTab.CustomAction" Location="Mscrm.HomepageGrid.contact.MainTab.Collaborate.Controls._children" Sequence="41">
              <Button Id="Isv.Grid.Contact.MainTab" Command="Isv.Grid.Contact.UpdateRecord.Command" LabelText="$LocLabels:Isv.Grid.Contact.UpdateRecord.LabelText" ToolTipTitle="$LocLabels:Isv.Grid.Contact.UpdateRecord.ToolTip" ToolTipDescription="$LocLabels:Isv.Grid.Contact.UpdateRecord.ToolTip" TemplateAlias="o1" Image16by16="/_imgs/ribbon/SendShortcut_16.png" Image32by32="/_imgs/ribbon/SendShortcut_32.png" />
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
          <CommandDefinition Id="Isv.Grid.Contact.UpdateRecord.Command">
              <EnableRule Id="Isv.Grid.Contact.OneSelected.EnableRule" />
              <DisplayRule Id="Isv.Grid.Contact.UpdateRecord.DisplayRule" />
              <JavaScriptFunction Library="$webresource:crm_json2.js" FunctionName="IsNAN">
              <JavaScriptFunction Library="$webresource:crm_jquery1.4.1.min.js" FunctionName="IsNAN">
              <JavaScriptFunction Library="$webresource:crm_contact.js" FunctionName="updateRecord">
                <CrmParameter Value="SelectedControlSelectedItemIds" />
          <TabDisplayRules />
            <DisplayRule Id="Isv.Grid.Contact.UpdateRecord.DisplayRule">
              <CrmClientTypeRule Type="Web" />
            <EnableRule Id="Isv.Grid.Contact.OneSelected.EnableRule">
              <SelectionCountRule AppliesTo="SelectedEntity" Minimum="1" />
          <LocLabel Id="Isv.Grid.Contact.UpdateRecord.LabelText">
              <Title languagecode="1033" description="Update Contacts" />
          <LocLabel Id="Isv.Grid.Contact.UpdateRecord.ToolTip">
              <Title languagecode="1033" description="Update the selected Contact records" />

After replacing the code save the file and import the solution into the CRM.

Make sure the jscript file and function name exists in your webresource. Below is my jscript function

function updateRecord(selectedIds) {
    if (selectedIds != null && selectedIds != "") {
        var strIds = selectedIds.toString();
        var arrIds = strIds.split(",");
        for (var indxIds = 0; indxIds < arrIds.length; indxIds++) {
        alert("Selected Records Updated Successfully");
    else {
        alert("No records selected!");

function updateContactRecords(contactId) {
    var objContact = new Object();
    objContact.CreditOnHold = true;

    var jsonEntity = window.JSON.stringify(objContact);

    var serverUrl = Xrm.Page.context.getServerUrl();
    var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc/ContactSet";
    var ODataPath = serverUrl + ODATA_ENDPOINT;
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: ODataPath + "(guid'" + contactId + "')",
        data: jsonEntity,
        beforeSend: function (XMLHttpRequest) {
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
            XMLHttpRequest.setRequestHeader("X-HTTP-Method", "MERGE");
        error: function (xmlHttpRequest, textStatus, errorThrown) {
            alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);

Click here to view all the <CrmParameter> values that can be passed.

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 )

Connecting to %s